mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
GT-3531 corrected DomainFile.isVersioned() for checked-out file.
Revised language upgrade support to facilitate optional context reset.
This commit is contained in:
parent
560ceb4d48
commit
687ce7f529
4 changed files with 54 additions and 16 deletions
|
@ -284,7 +284,7 @@ public class ProgramDB extends DomainObjectAdapterDB implements Program, ChangeM
|
|||
if (monitor == null) {
|
||||
monitor = TaskMonitorAdapter.DUMMY;
|
||||
}
|
||||
|
||||
|
||||
boolean success = false;
|
||||
try {
|
||||
int id = startTransaction("create program");
|
||||
|
@ -2284,8 +2284,9 @@ public class ProgramDB extends DomainObjectAdapterDB implements Program, ChangeM
|
|||
* Translate language
|
||||
* @param translator language translator, if null only re-disassembly will occur.
|
||||
* @param newCompilerSpecID new compiler specification which corresponds to new language, may be null.
|
||||
* @param monitor
|
||||
* @throws LockException
|
||||
* @param forceRedisassembly if true a redisassembly will be forced even if not required
|
||||
* @param monitor task monitor
|
||||
* @throws LockException if exclusive access is missing
|
||||
*/
|
||||
public void setLanguage(LanguageTranslator translator, CompilerSpecID newCompilerSpecID,
|
||||
boolean forceRedisassembly, TaskMonitor monitor) throws LockException {
|
||||
|
@ -2296,7 +2297,7 @@ public class ProgramDB extends DomainObjectAdapterDB implements Program, ChangeM
|
|||
try {
|
||||
setEventsEnabled(false);
|
||||
try {
|
||||
boolean notifyCodeManager = true;
|
||||
boolean redisassemblyRequired = true;
|
||||
int oldLanguageVersion = languageVersion;
|
||||
int oldLanguageMinorVersion = languageMinorVersion;
|
||||
if (translator != null) {
|
||||
|
@ -2311,7 +2312,7 @@ public class ProgramDB extends DomainObjectAdapterDB implements Program, ChangeM
|
|||
}
|
||||
else if (!forceRedisassembly && language.getVersion() == languageVersion &&
|
||||
language.getMinorVersion() == languageMinorVersion) {
|
||||
notifyCodeManager = false; // compiler spec change only
|
||||
redisassemblyRequired = false; // compiler spec change only
|
||||
Msg.info(this, "Setting compiler spec for Program " + getName() + ": " +
|
||||
compilerSpecID + " -> " + newCompilerSpecID);
|
||||
}
|
||||
|
@ -2350,15 +2351,14 @@ public class ProgramDB extends DomainObjectAdapterDB implements Program, ChangeM
|
|||
monitor.setProgress(0);
|
||||
ProgramRegisterContextDB contextMgr =
|
||||
(ProgramRegisterContextDB) getProgramContext();
|
||||
if (translator != null) {
|
||||
if (redisassemblyRequired) {
|
||||
contextMgr.setLanguage(translator, compilerSpec, memoryManager, monitor);
|
||||
}
|
||||
else {
|
||||
// force re-initialization
|
||||
contextMgr.initializeDefaultValues(language, compilerSpec);
|
||||
}
|
||||
|
||||
if (notifyCodeManager) {
|
||||
if (redisassemblyRequired) {
|
||||
Disassembler.clearUnimplementedPcodeWarnings(this, null, monitor);
|
||||
repairContext(oldLanguageVersion, oldLanguageMinorVersion, translator, monitor);
|
||||
monitor.setMessage("Updating instructions...");
|
||||
|
|
|
@ -72,12 +72,12 @@ public class ProgramRegisterContextDB extends AbstractStoredProgramContext imple
|
|||
}
|
||||
|
||||
if (openMode == DBConstants.UPGRADE && oldContextDataExists) {
|
||||
// TODO: Make sure upgrade is working correctly before uncommenting
|
||||
// try {
|
||||
// OldProgramContextDB.removeOldContextData(dbHandle);
|
||||
// } catch (IOException e) {
|
||||
// errorHandler.dbError(e);
|
||||
// }
|
||||
try {
|
||||
OldProgramContextDB.removeOldContextData(dbHandle);
|
||||
}
|
||||
catch (IOException e) {
|
||||
errorHandler.dbError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,6 +161,12 @@ public class ProgramRegisterContextDB extends AbstractStoredProgramContext imple
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Intialize context with default values defined by pspec and cspec.
|
||||
* NOTE: cspec values take precedence
|
||||
* @param lang processor language
|
||||
* @param compilerSpec compiler specification
|
||||
*/
|
||||
public void initializeDefaultValues(Language lang, CompilerSpec compilerSpec) {
|
||||
defaultRegisterValueMap.clear();
|
||||
lang.applyContextSettings(this);
|
||||
|
@ -288,9 +294,31 @@ public class ProgramRegisterContextDB extends AbstractStoredProgramContext imple
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform context upgrade due to a language change
|
||||
* @param translator language translator required by major upgrades (may be null)
|
||||
* @param newCompilerSpec new compiler specification
|
||||
* @param programMemory program memory
|
||||
* @param monitor task monitor
|
||||
* @throws CancelledException thrown if monitor cancelled
|
||||
*/
|
||||
public void setLanguage(LanguageTranslator translator, CompilerSpec newCompilerSpec,
|
||||
AddressSetView programMemory, TaskMonitor monitor) throws CancelledException {
|
||||
|
||||
if (translator == null) {
|
||||
Language lang = program.getLanguage();
|
||||
boolean clearContext = Boolean.valueOf(
|
||||
lang.getProperty(GhidraLanguagePropertyKeys.RESET_CONTEXT_ON_UPGRADE));
|
||||
if (clearContext) {
|
||||
RegisterValueStore store = registerValueMap.get(baseContextRegister);
|
||||
if (store != null) {
|
||||
store.clearAll();
|
||||
}
|
||||
}
|
||||
initializeDefaultValues(lang, newCompilerSpec);
|
||||
return;
|
||||
}
|
||||
|
||||
Language newLanguage = translator.getNewLanguage();
|
||||
|
||||
// Sort the registers by size so that largest come first.
|
||||
|
@ -309,8 +337,11 @@ public class ProgramRegisterContextDB extends AbstractStoredProgramContext imple
|
|||
continue;
|
||||
}
|
||||
|
||||
boolean clearContext = register.isProcessorContext() && Boolean.valueOf(
|
||||
newLanguage.getProperty(GhidraLanguagePropertyKeys.RESET_CONTEXT_ON_UPGRADE));
|
||||
|
||||
// Update storage range map
|
||||
if (!store.setLanguage(translator, monitor)) {
|
||||
if (clearContext || !store.setLanguage(translator, monitor)) {
|
||||
// Clear and remove old register value store
|
||||
Msg.warn(this,
|
||||
"WARNING! Discarding all context for register " + register.getName());
|
||||
|
|
|
@ -112,4 +112,11 @@ public final class GhidraLanguagePropertyKeys {
|
|||
* following the call. Non-returning functions can be detected in many cases.
|
||||
*/
|
||||
public static final String ENABLE_NO_RETURN_ANALYSIS = "enableNoReturnAnalysis";
|
||||
|
||||
/**
|
||||
* Property to indicate that all stored instruction context should be cleared
|
||||
* during a language upgrade operation which requires redisassembly.
|
||||
* NOTE: This is an experimental concept which may be removed in the future
|
||||
*/
|
||||
public static final String RESET_CONTEXT_ON_UPGRADE = "resetContextOnUpgrade";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue