diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/register/DebuggerRegistersProvider.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/register/DebuggerRegistersProvider.java index 3b654ae5ac..5464246871 100644 --- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/register/DebuggerRegistersProvider.java +++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/gui/register/DebuggerRegistersProvider.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -1146,8 +1146,7 @@ public class DebuggerRegistersProvider extends ComponentProviderAdapter if (mem == null) { return result; } - AddressSpace regSpace = - thread.getTrace().getBaseLanguage().getAddressFactory().getRegisterSpace(); + AddressSpace regSpace = thread.getTrace().getBaseAddressFactory().getRegisterSpace(); AddressSet everKnown = new AddressSet(); for (Entry entry : mem.getMostRecentStates( thread.getTrace().getTimeManager().getMaxSnap(), diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/model/TraceEventListener.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/model/TraceEventListener.java index dc6ff48b12..1879a3bf31 100644 --- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/model/TraceEventListener.java +++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/model/TraceEventListener.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -184,7 +184,7 @@ public class TraceEventListener extends AnnotatedDebuggerAttributeListener { long snap = recorder.getSnap(); String path = object.getJoinedPath("."); recorder.parTx.execute("Memory invalidated: " + path, () -> { - AddressSet set = trace.getBaseLanguage().getAddressFactory().getAddressSet(); + AddressSet set = trace.getBaseAddressFactory().getAddressSet(); memoryManager.setState(snap, set, TraceMemoryState.UNKNOWN); }, path); } diff --git a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingProviderTest.java b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingProviderTest.java index 1ed5706e5b..ab75f0e6ce 100644 --- a/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingProviderTest.java +++ b/Ghidra/Debug/Debugger/src/test/java/ghidra/app/plugin/core/debug/gui/listing/DebuggerListingProviderTest.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -1803,4 +1803,31 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTes waitForSwing(); assertFalse(listingPanel.isHoverShowing()); } + + @Test + public void testWithOverlaySpaces() throws Throwable { + createAndOpenTrace("DATA:BE:64:default"); + AddressSpace ram = tb.trace.getBaseAddressFactory().getDefaultAddressSpace(); + + AddressSpace ram0; + AddressSpace ram1; + try (Transaction tx = tb.startTransaction()) { + DBTraceMemoryManager mm = tb.trace.getMemoryManager(); + ram0 = mm.createOverlayAddressSpace("ram0", ram); + ram1 = mm.createOverlayAddressSpace("ram1", ram); + + mm.createRegion("Memory[0]", 0, tb.range(ram1, 0, 0x1000), + Set.of(TraceMemoryFlag.READ, TraceMemoryFlag.EXECUTE)); + mm.createRegion("Memory[1]", 0, tb.range(ram0, 0x1000, 0x2000), + Set.of(TraceMemoryFlag.READ, TraceMemoryFlag.WRITE)); + } + waitForDomainObject(tb.trace); + + traceManager.activateTrace(tb.trace); + waitForSwing(); + + assertEquals(ram0.getAddress(0x1002), listingProvider.getListingPanel() + .getListingModel() + .getAddressAfter(ram0.getAddress(0x1001))); + } } diff --git a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/listing/AbstractBaseDBTraceCodeUnitsMemoryView.java b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/listing/AbstractBaseDBTraceCodeUnitsMemoryView.java index 9fcaf2d460..9c3d37a39f 100644 --- a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/listing/AbstractBaseDBTraceCodeUnitsMemoryView.java +++ b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/listing/AbstractBaseDBTraceCodeUnitsMemoryView.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,6 +16,7 @@ package ghidra.trace.database.listing; import java.util.Collections; +import java.util.Iterator; import java.util.concurrent.locks.Lock; import generic.NestedIterator; @@ -258,8 +259,11 @@ public abstract class AbstractBaseDBTraceCodeUnitsMemoryView it = DBTraceUtils + .getAddressSet(manager.getTrace().getBaseAddressFactory(), address, false) + .iterator(false); + while (it.hasNext()) { + AddressRange range = it.next(); M m = getForSpace(range.getAddressSpace(), false); T candidate = m == null ? nullOrUndefined(snap, range.getMaxAddress()) : m.getFloor(snap, range.getMaxAddress()); @@ -303,7 +307,7 @@ public abstract class AbstractBaseDBTraceCodeUnitsMemoryView get(long snap, Address start, boolean forward) { - AddressFactory factory = manager.getBaseLanguage().getAddressFactory(); + AddressFactory factory = manager.getTrace().getBaseAddressFactory(); return get(snap, DBTraceUtils.getAddressSet(factory, start, forward), forward); } @@ -368,7 +372,7 @@ public abstract class AbstractBaseDBTraceCodeUnitsMemoryView get(long snap, boolean forward) { - return get(snap, manager.getBaseLanguage().getAddressFactory().getAddressSet(), forward); + return get(snap, manager.getTrace().getBaseAddressFactory().getAddressSet(), forward); } /** @@ -398,7 +402,7 @@ public abstract class AbstractBaseDBTraceCodeUnitsMemoryView new InstructionSet(manager.getBaseLanguage().getAddressFactory())); + s -> new InstructionSet(manager.getTrace().getBaseAddressFactory())); setPerSpace.addBlock(block); } AddressSet result = new AddressSet(); diff --git a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/AbstractDBTraceProgramViewListing.java b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/AbstractDBTraceProgramViewListing.java index a3263acf40..5b442f13b3 100644 --- a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/AbstractDBTraceProgramViewListing.java +++ b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/AbstractDBTraceProgramViewListing.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -159,7 +159,7 @@ public abstract class AbstractDBTraceProgramViewListing implements TraceProgramV protected AddressSet getAddressSet(Address start, boolean forward) { AddressFactory factory = program.getAddressFactory(); - AddressSet all = program.allAddresses; + AddressSetView all = program.getAllAddresses(); return forward ? factory.getAddressSet(start, all.getMaxAddress()) : factory.getAddressSet(all.getMinAddress(), start); @@ -281,7 +281,7 @@ public abstract class AbstractDBTraceProgramViewListing implements TraceProgramV } protected Iterator getCodeUnitIterator(boolean forward) { - AddressSetView set = program.allAddresses; + AddressSetView set = program.getAllAddresses(); return getCodeUnitIterator(forward ? set.getMinAddress() : set.getMaxAddress(), forward); } @@ -300,7 +300,7 @@ public abstract class AbstractDBTraceProgramViewListing implements TraceProgramV } protected Iterator getDataIterator(boolean forward) { - AddressSetView set = program.allAddresses; + AddressSetView set = program.getAllAddresses(); return getDataIterator(forward ? set.getMinAddress() : set.getMaxAddress(), forward); } diff --git a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramView.java b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramView.java index b8c3e62b49..a0d1fb2a07 100644 --- a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramView.java +++ b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramView.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -708,7 +708,8 @@ public class DBTraceProgramView implements TraceProgramView { protected final DomainObjectEventQueues eventQueues; protected EventTranslator eventTranslator; - protected final AddressSet allAddresses = new AddressSet(); + private volatile boolean allAddressesValid; + private volatile AddressSetView allAddresses;; protected final DBTraceProgramViewBookmarkManager bookmarkManager; protected final DBTraceProgramViewEquateTable equateTable; @@ -733,18 +734,14 @@ public class DBTraceProgramView implements TraceProgramView { Long versionTag = 0L; public DBTraceProgramView(DBTrace trace, long snap, CompilerSpec compilerSpec) { - for (AddressSpace space : trace.getBaseAddressFactory().getPhysicalSpaces()) { - if (space.getType() == AddressSpace.TYPE_OTHER) { - continue; - } - allAddresses.add(space.getMinAddress(), space.getMaxAddress()); - } this.trace = trace; this.snap = snap; this.languageID = compilerSpec.getLanguage().getLanguageID(); this.language = compilerSpec.getLanguage(); this.compilerSpec = compilerSpec; + checkRefreshAllAddresses(); + this.viewport = trace.createTimeViewport(); this.viewport.setSnap(snap); @@ -766,6 +763,25 @@ public class DBTraceProgramView implements TraceProgramView { } + protected void checkRefreshAllAddresses() { + if (this.allAddressesValid) { + return; + } + AddressSet allAddresses = new AddressSet(); + for (AddressSpace space : trace.getBaseAddressFactory().getPhysicalSpaces()) { + if (space.getType() != AddressSpace.TYPE_OTHER) { + allAddresses.add(space.getMinAddress(), space.getMaxAddress()); + } + } + this.allAddresses = allAddresses; + this.allAddressesValid = true; + } + + protected AddressSetView getAllAddresses() { + checkRefreshAllAddresses(); + return allAddresses; + } + protected void viewportChanged() { eventQueues.fireEvent(new DomainObjectChangeRecord(DomainObjectEvent.RESTORED)); } @@ -1500,11 +1516,13 @@ public class DBTraceProgramView implements TraceProgramView { public void updateMemoryAddSpaceBlock(AddressSpace space) { // Spaces not not time-bound. No visibility check. memory.updateAddSpaceBlock(space); + allAddressesValid = false; } public void updateMemoryDeleteSpaceBlock(AddressSpace space) { // Spaces not not time-bound. No visibility check. memory.updateDeleteSpaceBlock(space); + allAddressesValid = false; } public void updateMemoryRefreshBlocks() { diff --git a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewListing.java b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewListing.java index 1a0d08de61..deb4e548cf 100644 --- a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewListing.java +++ b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewListing.java @@ -4,9 +4,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,18 +15,16 @@ */ package ghidra.trace.database.program; -import ghidra.program.model.address.*; +import ghidra.program.model.address.Address; +import ghidra.program.model.address.AddressRange; import ghidra.trace.model.Lifespan; import ghidra.util.LockHold; import ghidra.util.exception.CancelledException; import ghidra.util.task.TaskMonitor; public class DBTraceProgramViewListing extends AbstractDBTraceProgramViewListing { - protected final AddressSet allMemory; - public DBTraceProgramViewListing(DBTraceProgramView program) { super(program, program.trace.getCodeManager()); - this.allMemory = program.getAddressFactory().getAddressSet(); } @Override @@ -61,7 +59,7 @@ public class DBTraceProgramViewListing extends AbstractDBTraceProgramViewListing // TODO: Delete this when the interface removes it public void clearAll(boolean clearContext, TaskMonitor monitor) { try (LockHold hold = program.trace.lockRead()) { - for (AddressRange range : allMemory) { + for (AddressRange range : program.getAddressFactory().getAddressSet()) { codeOperations.definedUnits() .clear(Lifespan.at(program.snap), range, clearContext, monitor); }