Merge remote-tracking branch

'origin/GP-4788_Dan_fixTraceOverlayAddressComparison--SQUASHED' (#6735)
This commit is contained in:
Ryan Kurtz 2024-08-14 12:48:24 -04:00
commit 21d0c5438a
8 changed files with 88 additions and 42 deletions

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -1146,8 +1146,7 @@ public class DebuggerRegistersProvider extends ComponentProviderAdapter
if (mem == null) { if (mem == null) {
return result; return result;
} }
AddressSpace regSpace = AddressSpace regSpace = thread.getTrace().getBaseAddressFactory().getRegisterSpace();
thread.getTrace().getBaseLanguage().getAddressFactory().getRegisterSpace();
AddressSet everKnown = new AddressSet(); AddressSet everKnown = new AddressSet();
for (Entry<TraceAddressSnapRange, TraceMemoryState> entry : mem.getMostRecentStates( for (Entry<TraceAddressSnapRange, TraceMemoryState> entry : mem.getMostRecentStates(
thread.getTrace().getTimeManager().getMaxSnap(), thread.getTrace().getTimeManager().getMaxSnap(),

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -184,7 +184,7 @@ public class TraceEventListener extends AnnotatedDebuggerAttributeListener {
long snap = recorder.getSnap(); long snap = recorder.getSnap();
String path = object.getJoinedPath("."); String path = object.getJoinedPath(".");
recorder.parTx.execute("Memory invalidated: " + path, () -> { recorder.parTx.execute("Memory invalidated: " + path, () -> {
AddressSet set = trace.getBaseLanguage().getAddressFactory().getAddressSet(); AddressSet set = trace.getBaseAddressFactory().getAddressSet();
memoryManager.setState(snap, set, TraceMemoryState.UNKNOWN); memoryManager.setState(snap, set, TraceMemoryState.UNKNOWN);
}, path); }, path);
} }

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -1803,4 +1803,31 @@ public class DebuggerListingProviderTest extends AbstractGhidraHeadedDebuggerTes
waitForSwing(); waitForSwing();
assertFalse(listingPanel.isHoverShowing()); 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)));
}
} }

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -16,6 +16,7 @@
package ghidra.trace.database.listing; package ghidra.trace.database.listing;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import generic.NestedIterator; import generic.NestedIterator;
@ -258,8 +259,11 @@ public abstract class AbstractBaseDBTraceCodeUnitsMemoryView<T extends DBTraceCo
*/ */
public T getFloor(long snap, Address address) { public T getFloor(long snap, Address address) {
try (LockHold hold = LockHold.lock(readLock())) { try (LockHold hold = LockHold.lock(readLock())) {
for (AddressRange range : DBTraceUtils.getAddressSet( Iterator<AddressRange> it = DBTraceUtils
manager.getBaseLanguage().getAddressFactory(), address, false)) { .getAddressSet(manager.getTrace().getBaseAddressFactory(), address, false)
.iterator(false);
while (it.hasNext()) {
AddressRange range = it.next();
M m = getForSpace(range.getAddressSpace(), false); M m = getForSpace(range.getAddressSpace(), false);
T candidate = m == null ? nullOrUndefined(snap, range.getMaxAddress()) T candidate = m == null ? nullOrUndefined(snap, range.getMaxAddress())
: m.getFloor(snap, range.getMaxAddress()); : m.getFloor(snap, range.getMaxAddress());
@ -303,7 +307,7 @@ public abstract class AbstractBaseDBTraceCodeUnitsMemoryView<T extends DBTraceCo
public T getCeiling(long snap, Address address) { public T getCeiling(long snap, Address address) {
try (LockHold hold = LockHold.lock(readLock())) { try (LockHold hold = LockHold.lock(readLock())) {
for (AddressRange range : DBTraceUtils.getAddressSet( for (AddressRange range : DBTraceUtils.getAddressSet(
manager.getBaseLanguage().getAddressFactory(), address, true)) { manager.getTrace().getBaseAddressFactory(), address, true)) {
M m = getForSpace(range.getAddressSpace(), false); M m = getForSpace(range.getAddressSpace(), false);
T candidate = m == null ? nullOrUndefined(snap, range.getMinAddress()) T candidate = m == null ? nullOrUndefined(snap, range.getMinAddress())
: m.getCeiling(snap, range.getMinAddress()); : m.getCeiling(snap, range.getMinAddress());
@ -333,7 +337,7 @@ public abstract class AbstractBaseDBTraceCodeUnitsMemoryView<T extends DBTraceCo
if (min.hasSameAddressSpace(max)) { if (min.hasSameAddressSpace(max)) {
return get(snap, new AddressRangeImpl(min, max), forward); return get(snap, new AddressRangeImpl(min, max), forward);
} }
return get(snap, manager.getBaseLanguage().getAddressFactory().getAddressSet(min, max), return get(snap, manager.getTrace().getBaseAddressFactory().getAddressSet(min, max),
forward); forward);
} }
@ -360,7 +364,7 @@ public abstract class AbstractBaseDBTraceCodeUnitsMemoryView<T extends DBTraceCo
* @see TraceBaseCodeUnitsView#get(long, Address, boolean) * @see TraceBaseCodeUnitsView#get(long, Address, boolean)
*/ */
public Iterable<? extends T> get(long snap, Address start, boolean forward) { public Iterable<? extends T> 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); return get(snap, DBTraceUtils.getAddressSet(factory, start, forward), forward);
} }
@ -368,7 +372,7 @@ public abstract class AbstractBaseDBTraceCodeUnitsMemoryView<T extends DBTraceCo
* @see TraceBaseCodeUnitsView#get(long, boolean) * @see TraceBaseCodeUnitsView#get(long, boolean)
*/ */
public Iterable<? extends T> get(long snap, boolean forward) { public Iterable<? extends T> 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<T extends DBTraceCo
*/ */
public AddressSetView getAddressSetView(long snap) { public AddressSetView getAddressSetView(long snap) {
AddressSet result = new AddressSet(); AddressSet result = new AddressSet();
for (AddressRange range : manager.getBaseLanguage().getAddressFactory().getAddressSet()) { for (AddressRange range : manager.getTrace().getBaseAddressFactory().getAddressSet()) {
M m = getForSpace(range.getAddressSpace(), false); M m = getForSpace(range.getAddressSpace(), false);
if (m == null) { if (m == null) {
result.add(emptyOrFullAddressSetUndefined(range)); result.add(emptyOrFullAddressSetUndefined(range));

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -75,7 +75,7 @@ public class DBTraceInstructionsMemoryView
for (InstructionBlock block : mappedSet) { for (InstructionBlock block : mappedSet) {
InstructionSet setPerSpace = InstructionSet setPerSpace =
breakDown.computeIfAbsent(block.getStartAddress().getAddressSpace(), breakDown.computeIfAbsent(block.getStartAddress().getAddressSpace(),
s -> new InstructionSet(manager.getBaseLanguage().getAddressFactory())); s -> new InstructionSet(manager.getTrace().getBaseAddressFactory()));
setPerSpace.addBlock(block); setPerSpace.addBlock(block);
} }
AddressSet result = new AddressSet(); AddressSet result = new AddressSet();

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 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) { protected AddressSet getAddressSet(Address start, boolean forward) {
AddressFactory factory = program.getAddressFactory(); AddressFactory factory = program.getAddressFactory();
AddressSet all = program.allAddresses; AddressSetView all = program.getAllAddresses();
return forward return forward
? factory.getAddressSet(start, all.getMaxAddress()) ? factory.getAddressSet(start, all.getMaxAddress())
: factory.getAddressSet(all.getMinAddress(), start); : factory.getAddressSet(all.getMinAddress(), start);
@ -281,7 +281,7 @@ public abstract class AbstractDBTraceProgramViewListing implements TraceProgramV
} }
protected Iterator<TraceCodeUnit> getCodeUnitIterator(boolean forward) { protected Iterator<TraceCodeUnit> getCodeUnitIterator(boolean forward) {
AddressSetView set = program.allAddresses; AddressSetView set = program.getAllAddresses();
return getCodeUnitIterator(forward ? set.getMinAddress() : set.getMaxAddress(), forward); return getCodeUnitIterator(forward ? set.getMinAddress() : set.getMaxAddress(), forward);
} }
@ -300,7 +300,7 @@ public abstract class AbstractDBTraceProgramViewListing implements TraceProgramV
} }
protected Iterator<TraceData> getDataIterator(boolean forward) { protected Iterator<TraceData> getDataIterator(boolean forward) {
AddressSetView set = program.allAddresses; AddressSetView set = program.getAllAddresses();
return getDataIterator(forward ? set.getMinAddress() : set.getMaxAddress(), forward); return getDataIterator(forward ? set.getMinAddress() : set.getMaxAddress(), forward);
} }

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 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 final DomainObjectEventQueues eventQueues;
protected EventTranslator eventTranslator; protected EventTranslator eventTranslator;
protected final AddressSet allAddresses = new AddressSet(); private volatile boolean allAddressesValid;
private volatile AddressSetView allAddresses;;
protected final DBTraceProgramViewBookmarkManager bookmarkManager; protected final DBTraceProgramViewBookmarkManager bookmarkManager;
protected final DBTraceProgramViewEquateTable equateTable; protected final DBTraceProgramViewEquateTable equateTable;
@ -733,18 +734,14 @@ public class DBTraceProgramView implements TraceProgramView {
Long versionTag = 0L; Long versionTag = 0L;
public DBTraceProgramView(DBTrace trace, long snap, CompilerSpec compilerSpec) { 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.trace = trace;
this.snap = snap; this.snap = snap;
this.languageID = compilerSpec.getLanguage().getLanguageID(); this.languageID = compilerSpec.getLanguage().getLanguageID();
this.language = compilerSpec.getLanguage(); this.language = compilerSpec.getLanguage();
this.compilerSpec = compilerSpec; this.compilerSpec = compilerSpec;
checkRefreshAllAddresses();
this.viewport = trace.createTimeViewport(); this.viewport = trace.createTimeViewport();
this.viewport.setSnap(snap); 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() { protected void viewportChanged() {
eventQueues.fireEvent(new DomainObjectChangeRecord(DomainObjectEvent.RESTORED)); eventQueues.fireEvent(new DomainObjectChangeRecord(DomainObjectEvent.RESTORED));
} }
@ -1500,11 +1516,13 @@ public class DBTraceProgramView implements TraceProgramView {
public void updateMemoryAddSpaceBlock(AddressSpace space) { public void updateMemoryAddSpaceBlock(AddressSpace space) {
// Spaces not not time-bound. No visibility check. // Spaces not not time-bound. No visibility check.
memory.updateAddSpaceBlock(space); memory.updateAddSpaceBlock(space);
allAddressesValid = false;
} }
public void updateMemoryDeleteSpaceBlock(AddressSpace space) { public void updateMemoryDeleteSpaceBlock(AddressSpace space) {
// Spaces not not time-bound. No visibility check. // Spaces not not time-bound. No visibility check.
memory.updateDeleteSpaceBlock(space); memory.updateDeleteSpaceBlock(space);
allAddressesValid = false;
} }
public void updateMemoryRefreshBlocks() { public void updateMemoryRefreshBlocks() {

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -15,18 +15,16 @@
*/ */
package ghidra.trace.database.program; 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.trace.model.Lifespan;
import ghidra.util.LockHold; import ghidra.util.LockHold;
import ghidra.util.exception.CancelledException; import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor; import ghidra.util.task.TaskMonitor;
public class DBTraceProgramViewListing extends AbstractDBTraceProgramViewListing { public class DBTraceProgramViewListing extends AbstractDBTraceProgramViewListing {
protected final AddressSet allMemory;
public DBTraceProgramViewListing(DBTraceProgramView program) { public DBTraceProgramViewListing(DBTraceProgramView program) {
super(program, program.trace.getCodeManager()); super(program, program.trace.getCodeManager());
this.allMemory = program.getAddressFactory().getAddressSet();
} }
@Override @Override
@ -61,7 +59,7 @@ public class DBTraceProgramViewListing extends AbstractDBTraceProgramViewListing
// TODO: Delete this when the interface removes it // TODO: Delete this when the interface removes it
public void clearAll(boolean clearContext, TaskMonitor monitor) { public void clearAll(boolean clearContext, TaskMonitor monitor) {
try (LockHold hold = program.trace.lockRead()) { try (LockHold hold = program.trace.lockRead()) {
for (AddressRange range : allMemory) { for (AddressRange range : program.getAddressFactory().getAddressSet()) {
codeOperations.definedUnits() codeOperations.definedUnits()
.clear(Lifespan.at(program.snap), range, clearContext, monitor); .clear(Lifespan.at(program.snap), range, clearContext, monitor);
} }