Merge remote-tracking branch 'origin/patch'

Conflicts:
	Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/emulation/DebuggerTracePcodeEmulator.java
This commit is contained in:
ghidra1 2021-09-07 18:58:48 -04:00
commit 976b54bb16
30 changed files with 204 additions and 203 deletions

View file

@ -195,7 +195,7 @@ public class SleighAssembler implements Assembler {
throw new AssemblyError(
"Context must be fully-specified (full length, no shift, no unknowns)");
}
if (lang.getContextBaseRegister() != null &&
if (lang.getContextBaseRegister() != Register.NO_CONTEXT &&
ctx.length() < lang.getContextBaseRegister().getMinimumByteSize()) {
throw new AssemblyError(
"Context must be fully-specified (full length, no shift, no unknowns)");

View file

@ -57,7 +57,7 @@ public class AssemblyDefaultContext implements DisassemblerContext, DefaultProgr
this.lang = lang;
this.at = at;
Register ctxreg = lang.getContextBaseRegister();
if (null == ctxreg) {
if (ctxreg == Register.NO_CONTEXT) {
this.defctx = AssemblyPatternBlock.nop();
this.curctx = AssemblyPatternBlock.nop();
}

View file

@ -90,7 +90,7 @@ public class SleighDebugLogger {
ContextCache contextCache = new ContextCache();
contextBaseRegister = language.getContextBaseRegister();
if (contextBaseRegister != null) {
if (contextBaseRegister != Register.NO_CONTEXT) {
contextCache.registerVariable(contextBaseRegister);
}

View file

@ -101,8 +101,8 @@ public class Emulate {
@SuppressWarnings("unchecked")
private void initInstuctionStateModifier() {
String classname = language.getProperty(
GhidraLanguagePropertyKeys.EMULATE_INSTRUCTION_STATE_MODIFIER_CLASS);
String classname = language
.getProperty(GhidraLanguagePropertyKeys.EMULATE_INSTRUCTION_STATE_MODIFIER_CLASS);
if (classname == null) {
return;
}
@ -245,7 +245,7 @@ public class Emulate {
*/
public RegisterValue getContextRegisterValue() {
Register contextReg = language.getContextBaseRegister();
if (contextReg == null) {
if (contextReg == Register.NO_CONTEXT) {
return null;
}
if (pseudoInstruction != null) {

View file

@ -58,7 +58,7 @@ public class EmulateDisassemblerContext implements DisassemblerContext {
public void setCurrentAddress(Address addr) {
if (contextReg == null) {
if (contextReg == Register.NO_CONTEXT) {
return;
}
RegisterValue partialValue = null;
@ -99,7 +99,7 @@ public class EmulateDisassemblerContext implements DisassemblerContext {
}
private void initContext() {
if (contextReg == null) {
if (contextReg == Register.NO_CONTEXT) {
return;
}
flowingContextRegisterMask = contextReg.getBaseMask().clone();
@ -203,8 +203,7 @@ public class EmulateDisassemblerContext implements DisassemblerContext {
}
@Override
public void setFutureRegisterValue(Address fromAddr, Address toAddr,
RegisterValue value) {
public void setFutureRegisterValue(Address fromAddr, Address toAddr, RegisterValue value) {
throw new UnsupportedOperationException();
}
}

View file

@ -819,8 +819,8 @@ public class ProgramDB extends DomainObjectAdapterDB implements Program, ChangeM
* @param oldValue the old datatype.
* @param newValue the new datatype.
*/
public void dataTypeChanged(long dataTypeID, int type, boolean isAutoChange,
Object oldValue, Object newValue) {
public void dataTypeChanged(long dataTypeID, int type, boolean isAutoChange, Object oldValue,
Object newValue) {
// TODO: do not need to record type changes for packed composite change which is in repsonse
// to component size or alignment change.
if (recordChanges && !isAutoChange) {
@ -2174,7 +2174,7 @@ public class ProgramDB extends DomainObjectAdapterDB implements Program, ChangeM
ProgramContext context = getProgramContext();
Register contextReg = context.getBaseContextRegister();
if (contextReg == null) {
if (contextReg == Register.NO_CONTEXT) {
return;
}
Register thumbBitReg = context.getRegister("TMode");

View file

@ -472,8 +472,11 @@ public class CodeManager implements ErrorHandler, ManagerDB {
if (prototype.hasDelaySlots()) {
// perform bounds check on entire delay slot instruction group
try {
endAddr = startAddr.addNoWrap(prototype.getFallThroughOffset(
protoInstr.getInstructionContext())).previous();
endAddr =
startAddr
.addNoWrap(prototype.getFallThroughOffset(
protoInstr.getInstructionContext()))
.previous();
}
catch (AddressOverflowException e) {
break;
@ -553,9 +556,10 @@ public class CodeManager implements ErrorHandler, ManagerDB {
InstructionPrototype prototype = lastInstruction.getPrototype();
if (prototype.hasDelaySlots()) {
try {
maxAddr = lastInstruction.getAddress().addNoWrap(
prototype.getFallThroughOffset(
lastInstruction.getInstructionContext())).previous();
maxAddr = lastInstruction.getAddress()
.addNoWrap(prototype.getFallThroughOffset(
lastInstruction.getInstructionContext()))
.previous();
}
catch (AddressOverflowException e) {
// ignore
@ -630,7 +634,7 @@ public class CodeManager implements ErrorHandler, ManagerDB {
prototype = protoMgr.getPrototype(protoID);
Register contextReg = contextMgr.getBaseContextRegister();
if (contextReg != null) {
if (contextReg != Register.NO_CONTEXT) {
try {
RegisterValue contextValue = context.getRegisterValue(contextReg);
Address start = address;
@ -2989,8 +2993,8 @@ public class CodeManager implements ErrorHandler, ManagerDB {
boolean isFallthrough =
(flowType.isJump() && flowAddr.equals(inst.getMaxAddress().next()));
if (!isFallthrough) {
mnemonicPrimaryRef = addDefaultMemoryReferenceIfMissing(inst, Reference.MNEMONIC,
flowAddr, flowType, oldRefList, mnemonicPrimaryRef);
mnemonicPrimaryRef = addDefaultMemoryReferenceIfMissing(inst,
Reference.MNEMONIC, flowAddr, flowType, oldRefList, mnemonicPrimaryRef);
}
}
}
@ -3020,8 +3024,8 @@ public class CodeManager implements ErrorHandler, ManagerDB {
* @param operandPrimaryRef current preferred primary reference for operand
* @return updated preferred primary address for operand (i.e., operandPrimaryRef)
*/
private Reference addDefaultMemoryReferenceIfMissing(Instruction inst,
int opIndex, Address refAddr, RefType refType, List<Reference> oldRefList,
private Reference addDefaultMemoryReferenceIfMissing(Instruction inst, int opIndex,
Address refAddr, RefType refType, List<Reference> oldRefList,
Reference operandPrimaryRef) {
Reference ref = removeOldReference(oldRefList, refAddr, opIndex, refType);

View file

@ -86,10 +86,6 @@ public class OldProgramContextDB implements ProgramContext, DefaultProgramContex
valueMaps = new HashMap<>();
baseContextRegister = language.getContextBaseRegister();
if (baseContextRegister == null) {
baseContextRegister = new Register("DEFAULT_CONTEXT", "DEFAULT_CONTEXT",
addrMap.getAddressFactory().getRegisterSpace().getAddress(0x0), 4, true, 0);
}
defaultDisassemblyContext = new RegisterValue(baseContextRegister);
initializeDefaultValues(language);

View file

@ -88,8 +88,7 @@ public class ProgramRegisterContextDB extends AbstractStoredProgramContext imple
return false;
}
private void upgrade(AddressMap addressMapExt, TaskMonitor monitor)
throws CancelledException {
private void upgrade(AddressMap addressMapExt, TaskMonitor monitor) throws CancelledException {
OldProgramContextDB oldContext =
new OldProgramContextDB(dbHandle, errorHandler, language, addressMapExt, lock);
@ -358,7 +357,7 @@ public class ProgramRegisterContextDB extends AbstractStoredProgramContext imple
// May need to fill-in blank context areas with a new specified context value
Register ctxReg = newLanguage.getContextBaseRegister();
if (ctxReg != null && translator.isValueTranslationRequired(ctxReg)) {
if (ctxReg != Register.NO_CONTEXT && translator.isValueTranslationRequired(ctxReg)) {
RegisterValue gapValue = new RegisterValue(ctxReg);
gapValue = translator.getNewRegisterValue(gapValue);
if (gapValue != null && gapValue.hasAnyValue()) {

View file

@ -254,7 +254,7 @@ public interface Language {
/**
* Returns processor context base register or null if one has not been defined by the
* language.
* @return base context register or null if not defined
* @return base context register or Register.NO_CONTEXT if not defined
*/
public Register getContextBaseRegister();

View file

@ -43,8 +43,9 @@ public class Register implements java.io.Serializable, Comparable<Register> {
/** Register can be used in SIMD operations **/
public final static int TYPE_VECTOR = 128;
public final static Register DEFAULT_CONTEXT =
new Register("DEFAULT_CONTEXT", "DEFAULT_CONTEXT", Address.NO_ADDRESS, 4, true, 0);
/** Register used to denote NO defined context for a language **/
public final static Register NO_CONTEXT =
new Register("NO_CONTEXT", "NO_CONTEXT", Address.NO_ADDRESS, 4, true, 0);
private String name;
private String description; // description of the register

View file

@ -127,7 +127,7 @@ public class RegisterManager {
}
// if there is no context register, force a default one
if (contextBaseRegister == null) {
contextBaseRegister = Register.DEFAULT_CONTEXT;
contextBaseRegister = Register.NO_CONTEXT;
}
// handle the register size 0 case;
Collections.reverse(registerListSortedBySize);

View file

@ -50,8 +50,8 @@ public class InstructionUtils {
FlowType flowType = instruction.getFlowType();
textBuf.append("\nFlow Type : " + flowType.toString());
FlowOverride flowOverride = instruction.getFlowOverride();
if (flowOverride != FlowOverride.NONE &&
instruction.getPrototype().getFlowType(instruction.getInstructionContext()) != flowType) {
if (flowOverride != FlowOverride.NONE && instruction.getPrototype()
.getFlowType(instruction.getInstructionContext()) != flowType) {
textBuf.append("\n >>> reflects " + flowOverride + " flow override");
}
Address fallAddr = instruction.getFallThrough();
@ -62,20 +62,20 @@ public class InstructionUtils {
textBuf.append("\nDelay slot depth : " + instruction.getDelaySlotDepth() +
(instruction.isInDelaySlot() ? " in slot" : ""));
textBuf.append(
"\nHash : " + Integer.toHexString(instruction.getPrototype().hashCode())).append(
'\n');
"\nHash : " + Integer.toHexString(instruction.getPrototype().hashCode()))
.append('\n');
textBuf.append("\nInput Objects:\n" +
getString(getFormatedInstructionObjects(instruction, true), true));
textBuf.append("\nResult Objects:\n" +
getString(getFormatedInstructionObjects(instruction, false), true));
textBuf.append(
"\nConstructor Line #'s:\n" + getString(debug.getConstructorLineNumbers(), true)).append(
'\n');
"\nConstructor Line #'s:\n" + getString(debug.getConstructorLineNumbers(), true))
.append('\n');
textBuf.append("\nByte Length : " + instruction.getLength());
try {
textBuf.append("\nInstr Bytes : " +
SleighDebugLogger.getFormattedBytes(instruction.getBytes()));
textBuf.append(
"\nInstr Bytes : " + SleighDebugLogger.getFormattedBytes(instruction.getBytes()));
textBuf.append("\nMask : " + debug.getFormattedInstructionMask(-1));
textBuf.append("\nMasked Bytes: " + debug.getFormattedMaskedValue(-1)).append('\n');
}
@ -93,10 +93,11 @@ public class InstructionUtils {
* @param instr
* @return formatted context data
*/
public static String getFormattedContextRegisterValueBreakout(Instruction instr, String indent) {
public static String getFormattedContextRegisterValueBreakout(Instruction instr,
String indent) {
ProgramContext programContext = instr.getProgram().getProgramContext();
Register contextReg = programContext.getBaseContextRegister();
if (contextReg == null) {
if (contextReg == Register.NO_CONTEXT) {
return indent + "[Instruction context not defined]";
}
return getFormattedRegisterValueBits(instr.getRegisterValue(contextReg), indent);

View file

@ -425,9 +425,9 @@ public abstract class LanguageTranslatorAdapter implements LanguageTranslator {
return false;
}
Register newContextReg = getNewLanguage().getContextBaseRegister();
if (newContextReg != null) {
if (newContextReg != Register.NO_CONTEXT) {
Register oldContextReg = getOldLanguage().getContextBaseRegister();
if (oldContextReg == null ||
if (oldContextReg == Register.NO_CONTEXT ||
!isSameRegisterConstruction(oldContextReg, newContextReg)) {
Msg.error(this, "Translator can not map context register: " + this);
return false;

View file

@ -143,8 +143,8 @@ public class OldLanguageFactory {
langSvc.getLanguageDescription(oldLang.getLanguageID());
if (curDescr.getVersion() <= oldDescr.getVersion()) {
// Ignore old versions which are inappropriate
log.warn("WARNING! Ignoring old language spec, version still exists: " +
oldLang);
log.warn(
"WARNING! Ignoring old language spec, version still exists: " + oldLang);
continue;
}
}
@ -208,8 +208,8 @@ public class OldLanguageFactory {
* @throws IOException if file error occurs
* @throws LanguageNotFoundException if lang is unknown to DefaultLanguageService
*/
public static void createOldLanguageFile(Language lang, File file) throws IOException,
LanguageNotFoundException {
public static void createOldLanguageFile(Language lang, File file)
throws IOException, LanguageNotFoundException {
LanguageService languageService = DefaultLanguageService.getLanguageService();
if (lang instanceof OldLanguage) {
@ -272,7 +272,7 @@ public class OldLanguageFactory {
Register contextReg = lang.getContextBaseRegister();
Element registersElement = new Element("registers");
if (contextReg != null) {
if (contextReg != Register.NO_CONTEXT) {
Element ctxElement = getRegisterElement(contextReg);
int contextBitLength = contextReg.getBitLength();
for (Register bitReg : contextReg.getChildRegisters()) {

View file

@ -160,7 +160,7 @@ class SimpleLanguageTranslator extends LanguageTranslatorAdapter {
return super.getNewRegisterValue(oldRegisterValue);
}
Register newContextReg = getNewLanguage().getContextBaseRegister();
if (newContextReg == null || (clearAllContext && contextSettings == null)) {
if (newContextReg == Register.NO_CONTEXT || (clearAllContext && contextSettings == null)) {
return null;
}
RegisterValue newValue = null;
@ -220,8 +220,8 @@ class SimpleLanguageTranslator extends LanguageTranslatorAdapter {
LanguagePostUpgradeInstructionHandler.class.getName());
}
Constructor<?> constructor = handlerClass.getConstructor(new Class<?>[] { Program.class });
return (LanguagePostUpgradeInstructionHandler) constructor.newInstance(
new Object[] { program });
return (LanguagePostUpgradeInstructionHandler) constructor
.newInstance(new Object[] { program });
}
@Override