Merge remote-tracking branch 'origin/GP-0_Dan_testFixed20210907_1' into patch

This commit is contained in:
Ryan Kurtz 2021-09-07 12:38:13 -04:00
commit 5e0c5ee3fc
5 changed files with 33 additions and 23 deletions

View File

@ -291,12 +291,12 @@ public class TracePcodeEmulatorTest extends AbstractGhidraHeadlessIntegrationTes
}
/**
* This tests an language without a contextreg
* This tests a language without a real contextreg
*/
@Test
public void testIMM() throws Throwable {
try (ToyDBTraceBuilder tb = new ToyDBTraceBuilder("Test", "Toy:BE:64:default")) {
assertNull(tb.language.getContextBaseRegister());
assertEquals(Register.DEFAULT_CONTEXT, tb.language.getContextBaseRegister());
TraceThread thread = initTrace(tb,
List.of(

View File

@ -1195,8 +1195,8 @@ public class DBTraceCodeUnitTest extends AbstractGhidraHeadlessIntegrationTest
i4004 = b.addInstruction(0, b.addr(0x4004), b.language, b.buf(0xf4, 0));
}
// TODO: Test with context
assertNull(i4004.getBaseContextRegister());
// TODO: Test with non-default context
assertEquals(Register.DEFAULT_CONTEXT, i4004.getBaseContextRegister());
assertEquals(b.language.getRegisters(), i4004.getRegisters());
assertEquals(r4, i4004.getRegister("r4"));

View File

@ -126,7 +126,7 @@ public class DefaultPcodeThread<T> implements PcodeThread<T> {
this.pc = language.getProgramCounter();
this.contextreg = language.getContextBaseRegister();
if (contextreg != null) {
if (contextreg != Register.DEFAULT_CONTEXT) {
defaultContext = new ProgramContextImpl(language);
language.applyContextSettings(defaultContext);
this.context = defaultContext.getDefaultDisassemblyContext();
@ -190,7 +190,7 @@ public class DefaultPcodeThread<T> implements PcodeThread<T> {
@Override
public void overrideContextWithDefault() {
if (contextreg != null) {
if (contextreg != Register.DEFAULT_CONTEXT) {
overrideContext(defaultContext.getDefaultValue(contextreg, counter));
}
}
@ -206,7 +206,7 @@ public class DefaultPcodeThread<T> implements PcodeThread<T> {
long offset = arithmetic.toConcrete(state.getVar(pc)).longValue();
setCounter(language.getDefaultSpace().getAddress(offset));
if (contextreg != null) {
if (contextreg != Register.DEFAULT_CONTEXT) {
try {
BigInteger ctx = arithmetic.toConcrete(state.getVar(contextreg));
assignContext(new RegisterValue(contextreg, ctx));
@ -271,7 +271,7 @@ public class DefaultPcodeThread<T> implements PcodeThread<T> {
if (frame.isFallThrough()) {
overrideCounter(counter.addWrap(decoder.getLastLengthWithDelays()));
}
if (contextreg != null) {
if (contextreg != Register.DEFAULT_CONTEXT) {
overrideContext(instruction.getRegisterValue(contextreg));
}
postExecuteInstruction();

View File

@ -43,6 +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);
private String name;
private String description; // description of the register
private Address address; // smallest address containing bits for this register

View File

@ -32,7 +32,7 @@ public class RegisterManager {
private Map<Address, List<Register>> registerAddressMap =
new HashMap<Address, List<Register>>();
/**List of vector registers, sorted first by size and then by offset**/
/** List of vector registers, sorted first by size and then by offset **/
private List<Register> sortedVectorRegisters;
class RegisterSizeKey {
@ -80,10 +80,11 @@ public class RegisterManager {
/**
* Construct RegisterManager
* @param registers all defined registers with appropriate parent-child relationships
* properly established.
* @param registerNameMap a complete name-to-register map including all register aliases
* and alternate spellings (e.g., case-variations)
*
* @param registers all defined registers with appropriate parent-child relationships properly
* established.
* @param registerNameMap a complete name-to-register map including all register aliases and
* alternate spellings (e.g., case-variations)
*/
RegisterManager(List<Register> registers, Map<String, Register> registerNameMap) {
this.registers = Collections.unmodifiableList(registers);
@ -126,8 +127,7 @@ public class RegisterManager {
}
// if there is no context register, force a default one
if (contextBaseRegister == null) {
contextBaseRegister =
new Register("DEFAULT_CONTEXT", "DEFAULT_CONTEXT", Address.NO_ADDRESS, 4, true, 0);
contextBaseRegister = Register.DEFAULT_CONTEXT;
}
// handle the register size 0 case;
Collections.reverse(registerListSortedBySize);
@ -156,6 +156,7 @@ public class RegisterManager {
/**
* Get context base-register
*
* @return context base register or null if one has not been defined by the language.
*/
public Register getContextBaseRegister() {
@ -163,7 +164,9 @@ public class RegisterManager {
}
/**
* Get unsorted unmodifiable list of all processor context registers (include base context register and children)
* Get unsorted unmodifiable list of all processor context registers (include base context
* register and children)
*
* @return all processor context registers
*/
public List<Register> getContextRegisters() {
@ -171,9 +174,8 @@ public class RegisterManager {
}
/**
* Get an alphabetical sorted unmodifiable list of original register names
* (including context registers). Names correspond to orignal register
* name and not aliases which may be defined.
* Get an alphabetical sorted unmodifiable list of original register names (including context
* registers). Names correspond to orignal register name and not aliases which may be defined.
*
* @return alphabetical sorted unmodifiable list of original register names.
*/
@ -183,6 +185,7 @@ public class RegisterManager {
/**
* Returns the largest register located at the specified address
*
* @param addr register address
* @return register or null if not found
*/
@ -222,6 +225,7 @@ public class RegisterManager {
/**
* Get register by address and size
*
* @param addr register address
* @param size register size
* @return register or null if not found
@ -235,9 +239,9 @@ public class RegisterManager {
}
/**
* Get register by name. A semi-case-insensitive lookup is performed.
* The specified name must match either the case-sensitive name or
* be entirely lowercase or uppercase.
* Get register by name. A semi-case-insensitive lookup is performed. The specified name must
* match either the case-sensitive name or be entirely lowercase or uppercase.
*
* @param name register name
* @return register or null if not found
*/
@ -247,6 +251,7 @@ public class RegisterManager {
/**
* Get all registers as an unsorted unmodifiable list.
*
* @return unmodifiable list of all registers defined
*/
public List<Register> getRegisters() {
@ -255,7 +260,8 @@ public class RegisterManager {
/**
* Get an unmodifiable list of all vector registers indentified by the processor specification
* in sorted order based upon address and size.
* in sorted order based upon address and size.
*
* @return all vector registers as unmodifiable list
*/
public List<Register> getSortedVectorRegisters() {
@ -274,6 +280,7 @@ public class RegisterManager {
/**
* Compares two vector registers, first by size (descending) and then by offset (ascending).
*
* @param reg1 vector register
* @param reg2 vector register
* @return result of comparison