GP-2430: Allow NO_ADDRESS in most Trace managers.

This commit is contained in:
Dan 2022-08-10 11:09:21 -04:00
parent c523b2b9d4
commit 2b140b7f22
4 changed files with 38 additions and 7 deletions

View file

@ -229,6 +229,9 @@ public class DBTrace extends DBCachedDomainObjectAdapter implements Trace, Trace
if (as == AddressSpace.OTHER_SPACE) { if (as == AddressSpace.OTHER_SPACE) {
return; return;
} }
if (as == Address.NO_ADDRESS.getAddressSpace()) {
return;
}
if (baseAddressFactory.getAddressSpace(as.getSpaceID()) != as) { if (baseAddressFactory.getAddressSpace(as.getSpaceID()) != as) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"AddressSpace '" + as + "' is not in this trace (language=" + getBaseLanguage() + "AddressSpace '" + as + "' is not in this trace (language=" + getBaseLanguage() +

View file

@ -25,8 +25,7 @@ import org.apache.commons.lang3.tuple.Pair;
import db.DBHandle; import db.DBHandle;
import db.DBRecord; import db.DBRecord;
import generic.CatenatedCollection; import generic.CatenatedCollection;
import ghidra.program.model.address.AddressFactory; import ghidra.program.model.address.*;
import ghidra.program.model.address.AddressSpace;
import ghidra.program.model.lang.Language; import ghidra.program.model.lang.Language;
import ghidra.trace.database.*; import ghidra.trace.database.*;
import ghidra.trace.database.thread.DBTraceThreadManager; import ghidra.trace.database.thread.DBTraceThreadManager;
@ -42,6 +41,8 @@ import ghidra.util.task.TaskMonitor;
public abstract class AbstractDBTraceSpaceBasedManager<M extends DBTraceSpaceBased, R extends M> public abstract class AbstractDBTraceSpaceBasedManager<M extends DBTraceSpaceBased, R extends M>
implements DBTraceManager { implements DBTraceManager {
protected static final AddressSpace NO_ADDRESS_SPACE = Address.NO_ADDRESS.getAddressSpace();
@DBAnnotatedObjectInfo(version = 0) @DBAnnotatedObjectInfo(version = 0)
public static class DBTraceSpaceEntry extends DBAnnotatedObject { public static class DBTraceSpaceEntry extends DBAnnotatedObject {
static final String SPACE_COLUMN_NAME = "Space"; static final String SPACE_COLUMN_NAME = "Space";
@ -127,7 +128,13 @@ public abstract class AbstractDBTraceSpaceBasedManager<M extends DBTraceSpaceBas
protected void loadSpaces() throws VersionException, IOException { protected void loadSpaces() throws VersionException, IOException {
for (DBTraceSpaceEntry ent : spaceStore.asMap().values()) { for (DBTraceSpaceEntry ent : spaceStore.asMap().values()) {
AddressFactory addressFactory = trace.getBaseAddressFactory(); AddressFactory addressFactory = trace.getBaseAddressFactory();
AddressSpace space = addressFactory.getAddressSpace(ent.spaceName); AddressSpace space;
if (NO_ADDRESS_SPACE.getName().equals(ent.spaceName)) {
space = NO_ADDRESS_SPACE;
}
else {
space = addressFactory.getAddressSpace(ent.spaceName);
}
if (space == null) { if (space == null) {
Msg.error(this, "Space " + ent.spaceName + " does not exist in trace (language=" + Msg.error(this, "Space " + ent.spaceName + " does not exist in trace (language=" +
baseLanguage + ")."); baseLanguage + ").");
@ -162,8 +169,8 @@ public abstract class AbstractDBTraceSpaceBasedManager<M extends DBTraceSpaceBas
protected M getForSpace(AddressSpace space, boolean createIfAbsent) { protected M getForSpace(AddressSpace space, boolean createIfAbsent) {
trace.assertValidSpace(space); trace.assertValidSpace(space);
if (!space.isMemorySpace()) { if (!space.isMemorySpace() && space != Address.NO_ADDRESS.getAddressSpace()) {
throw new IllegalArgumentException("Space must be a memory space"); throw new IllegalArgumentException("Space must be a memory space or NO_ADDRESS");
} }
if (space.isRegisterSpace()) { if (space.isRegisterSpace()) {
throw new IllegalArgumentException("Space cannot be register space"); throw new IllegalArgumentException("Space cannot be register space");

View file

@ -41,8 +41,8 @@ public interface DBTraceDelegatingManager<M> {
} }
default void checkIsInMemory(AddressSpace space) { default void checkIsInMemory(AddressSpace space) {
if (!space.isMemorySpace()) { if (!space.isMemorySpace() && space != Address.NO_ADDRESS.getAddressSpace()) {
throw new IllegalArgumentException("Address must be in memory"); throw new IllegalArgumentException("Address must be in memory or NO_ADDRESS");
} }
} }

View file

@ -25,6 +25,7 @@ import org.junit.*;
import com.google.common.collect.Range; import com.google.common.collect.Range;
import ghidra.program.model.address.Address;
import ghidra.program.model.util.TypeMismatchException; import ghidra.program.model.util.TypeMismatchException;
import ghidra.test.AbstractGhidraHeadlessIntegrationTest; import ghidra.test.AbstractGhidraHeadlessIntegrationTest;
import ghidra.trace.database.ToyDBTraceBuilder; import ghidra.trace.database.ToyDBTraceBuilder;
@ -375,4 +376,24 @@ public class DBTraceAddressPropertyManagerTest extends AbstractGhidraHeadlessInt
public void testSaveableMap() throws Exception { public void testSaveableMap() throws Exception {
doTestMap(MySaveable.class, new MySaveable(6, "MyString")); doTestMap(MySaveable.class, new MySaveable(6, "MyString"));
} }
@Test
public void testStringMapAtNoAdress() throws Exception {
TracePropertyMap<String> map;
try (UndoableTransaction tid = tb.startTransaction()) {
map = propertyManager.createPropertyMap("MyProp", String.class);
map.set(Range.atLeast(0L), Address.NO_ADDRESS, "Value");
}
assertEquals("Value", map.get(4, Address.NO_ADDRESS));
File file = tb.save();
try (ToyDBTraceBuilder tb = new ToyDBTraceBuilder(file)) {
TracePropertyMap<String> map2 =
tb.trace.getAddressPropertyManager().getPropertyMap("MyProp", String.class);
assertEquals("Value", map2.get(4, Address.NO_ADDRESS));
}
}
} }