mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-24 01:50:52 +08:00
Merge remote-tracking branch 'origin/GP-6131_Dan_fixCheckIsInMemory--SQUASHED'
This commit is contained in:
-17
@@ -40,16 +40,8 @@ public interface DBTraceDelegatingManager<M> {
|
||||
boolean test(T t) throws E;
|
||||
}
|
||||
|
||||
default void checkIsInMemory(AddressSpace space) {
|
||||
if (!space.isMemorySpace() && space != Address.NO_ADDRESS.getAddressSpace()) {
|
||||
throw new IllegalArgumentException(
|
||||
"Address must be in memory or NO_ADDRESS. Got " + space);
|
||||
}
|
||||
}
|
||||
|
||||
default <T, E extends Throwable> T delegateWrite(AddressSpace space, ExcFunction<M, T, E> func)
|
||||
throws E {
|
||||
checkIsInMemory(space);
|
||||
try (LockHold hold = LockHold.lock(writeLock())) {
|
||||
M m = getForSpace(space, true);
|
||||
return func.apply(m);
|
||||
@@ -58,7 +50,6 @@ public interface DBTraceDelegatingManager<M> {
|
||||
|
||||
default <E extends Throwable> void delegateWriteV(AddressSpace space, ExcConsumer<M, E> func)
|
||||
throws E {
|
||||
checkIsInMemory(space);
|
||||
try (LockHold hold = LockHold.lock(writeLock())) {
|
||||
M m = getForSpace(space, true);
|
||||
func.accept(m);
|
||||
@@ -66,7 +57,6 @@ public interface DBTraceDelegatingManager<M> {
|
||||
}
|
||||
|
||||
default int delegateWriteI(AddressSpace space, ToIntFunction<M> func) {
|
||||
checkIsInMemory(space);
|
||||
try (LockHold hold = LockHold.lock(writeLock())) {
|
||||
M m = getForSpace(space, true);
|
||||
return func.applyAsInt(m);
|
||||
@@ -89,7 +79,6 @@ public interface DBTraceDelegatingManager<M> {
|
||||
|
||||
default <T, E extends Throwable> T delegateRead(AddressSpace space,
|
||||
ExcFunction<M, T, E> func, T ifNull) throws E {
|
||||
checkIsInMemory(space);
|
||||
try (LockHold hold = LockHold.lock(readLock())) {
|
||||
M m = getForSpace(space, false);
|
||||
if (m == null) {
|
||||
@@ -101,7 +90,6 @@ public interface DBTraceDelegatingManager<M> {
|
||||
|
||||
default <T, E extends Throwable> T delegateReadOr(AddressSpace space, ExcFunction<M, T, E> func,
|
||||
ExcSupplier<T, E> ifNull) throws E {
|
||||
checkIsInMemory(space);
|
||||
try (LockHold hold = LockHold.lock(readLock())) {
|
||||
M m = getForSpace(space, false);
|
||||
if (m == null) {
|
||||
@@ -112,7 +100,6 @@ public interface DBTraceDelegatingManager<M> {
|
||||
}
|
||||
|
||||
default int delegateReadI(AddressSpace space, ToIntFunction<M> func, int ifNull) {
|
||||
checkIsInMemory(space);
|
||||
try (LockHold hold = LockHold.lock(readLock())) {
|
||||
M m = getForSpace(space, false);
|
||||
if (m == null) {
|
||||
@@ -123,7 +110,6 @@ public interface DBTraceDelegatingManager<M> {
|
||||
}
|
||||
|
||||
default int delegateReadI(AddressSpace space, ToIntFunction<M> func, IntSupplier ifNull) {
|
||||
checkIsInMemory(space);
|
||||
try (LockHold hold = LockHold.lock(readLock())) {
|
||||
M m = getForSpace(space, false);
|
||||
if (m == null) {
|
||||
@@ -134,7 +120,6 @@ public interface DBTraceDelegatingManager<M> {
|
||||
}
|
||||
|
||||
default boolean delegateReadB(AddressSpace space, Predicate<M> func, boolean ifNull) {
|
||||
checkIsInMemory(space);
|
||||
try (LockHold hold = LockHold.lock(readLock())) {
|
||||
M m = getForSpace(space, false);
|
||||
if (m == null) {
|
||||
@@ -146,7 +131,6 @@ public interface DBTraceDelegatingManager<M> {
|
||||
|
||||
default <E extends Throwable> void delegateDeleteV(AddressSpace space, ExcConsumer<M, E> func)
|
||||
throws E {
|
||||
checkIsInMemory(space);
|
||||
try (LockHold hold = LockHold.lock(writeLock())) {
|
||||
M m = getForSpace(space, false);
|
||||
if (m == null) {
|
||||
@@ -157,7 +141,6 @@ public interface DBTraceDelegatingManager<M> {
|
||||
}
|
||||
|
||||
default boolean delegateDeleteB(AddressSpace space, Predicate<M> func, boolean ifNull) {
|
||||
checkIsInMemory(space);
|
||||
try (LockHold hold = LockHold.lock(writeLock())) {
|
||||
M m = getForSpace(space, false);
|
||||
if (m == null) {
|
||||
|
||||
-16
@@ -65,22 +65,6 @@ public class DBTraceReferenceManager extends AbstractDBTraceSpaceBasedManager<DB
|
||||
return new DBTraceReferenceSpace(this, dbh, space, ent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that a "from" address is in memory
|
||||
*
|
||||
* <p>
|
||||
* NOTE: To manage references from registers, you must use
|
||||
* {@link #getReferenceRegisterSpace(TraceThread, boolean)}, which requires a thread.
|
||||
*
|
||||
* @param space the space of the address to check
|
||||
*/
|
||||
@Override
|
||||
public void checkIsInMemory(AddressSpace space) {
|
||||
if (!space.isMemorySpace()) {
|
||||
throw new IllegalArgumentException("Address must be in memory.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DBTraceReferenceSpace getForSpace(AddressSpace space, boolean createIfAbsent) {
|
||||
return super.getForSpace(space, createIfAbsent);
|
||||
|
||||
+8
-1
@@ -1435,12 +1435,19 @@ public class DBTraceCodeManagerTest extends AbstractGhidraHeadlessIntegrationTes
|
||||
frameCode = manager.getCodeRegisterSpace(stack.getFrame(0, 1, false), true);
|
||||
assertNotEquals(regCode, frameCode);
|
||||
dR5 = frameCode.definedData()
|
||||
.create(Lifespan.nowOn(0), b.language.getRegister("r5"), LongDataType.dataType);
|
||||
.create(Lifespan.nowOn(0), b.reg("r5"), LongDataType.dataType);
|
||||
}
|
||||
|
||||
assertEquals(1, frameCode.getFrameLevel());
|
||||
assertEquals(thread, frameCode.getThread());
|
||||
assertEquals(List.of(dR5), list(frameCode.definedUnits().get(0, true)));
|
||||
|
||||
// Manager should be able to delegate to regs by space, too, now that we use overlays.
|
||||
Address aR5 =
|
||||
b.host.getConventionalRegisterRange(frameCode.space, b.reg("r5")).getMinAddress();
|
||||
assertEquals(dR5, manager.definedData().getAt(0, aR5));
|
||||
// TODO: Given the line above succeeding, this ought to pass, but it doesn't.
|
||||
// assertEquals(List.of(dR5), list(manager.definedUnits().get(0, true)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+13
-3
@@ -18,10 +18,13 @@ package ghidra.trace.database.memory;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import db.Transaction;
|
||||
import ghidra.program.model.address.Address;
|
||||
import ghidra.program.model.lang.*;
|
||||
import ghidra.trace.model.Lifespan;
|
||||
import ghidra.trace.model.guest.TraceGuestPlatform;
|
||||
@@ -62,9 +65,9 @@ public abstract class AbstractDBTraceMemoryManagerRegistersTest
|
||||
|
||||
@Test
|
||||
public void testRegisters() throws Exception {
|
||||
Register r0 = b.language.getRegister("r0");
|
||||
Register r0h = b.language.getRegister("r0h");
|
||||
Register r0l = b.language.getRegister("r0l");
|
||||
Register r0 = b.reg("r0");
|
||||
Register r0h = b.reg("r0h");
|
||||
Register r0l = b.reg("r0l");
|
||||
|
||||
TraceThread thread;
|
||||
try (Transaction tx = b.startTransaction()) {
|
||||
@@ -103,6 +106,13 @@ public abstract class AbstractDBTraceMemoryManagerRegistersTest
|
||||
frame.setValue(0, new RegisterValue(r0, new BigInteger("1032547698BADCFE", 16)));
|
||||
assertEquals(new BigInteger("1032547698BADCFE", 16),
|
||||
frame.getValue(0, r0).getUnsignedValue());
|
||||
|
||||
Address aR0 = b.host.getConventionalRegisterRange(frame.space, r0).getMinAddress();
|
||||
ByteBuffer buf = ByteBuffer.allocate(r0.getNumBytes());
|
||||
memory.getBytes(0, aR0, buf);
|
||||
buf.flip();
|
||||
buf.order(b.language.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
|
||||
assertEquals(0x1032547698BADCFEL, buf.getLong(0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user