mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 02:39:44 +02:00
GP-480: Added breakpoint manager tests. Fixed getThreads().
This commit is contained in:
parent
f1b200fbfd
commit
88c94f16a6
2 changed files with 229 additions and 84 deletions
|
@ -207,6 +207,7 @@ public class DBTraceBreakpoint
|
||||||
Msg.warn(this, "Thread " + threadKeys[i] +
|
Msg.warn(this, "Thread " + threadKeys[i] +
|
||||||
" has been deleted since creating this breakpoint.");
|
" has been deleted since creating this breakpoint.");
|
||||||
}
|
}
|
||||||
|
threads.add(t);
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableSet(threads);
|
return Collections.unmodifiableSet(threads);
|
||||||
}
|
}
|
||||||
|
@ -287,32 +288,41 @@ public class DBTraceBreakpoint
|
||||||
public DBTraceBreakpoint splitAndSet(long snap, boolean en,
|
public DBTraceBreakpoint splitAndSet(long snap, boolean en,
|
||||||
Collection<TraceBreakpointKind> kinds) {
|
Collection<TraceBreakpointKind> kinds) {
|
||||||
DBTraceBreakpoint that;
|
DBTraceBreakpoint that;
|
||||||
Range<Long> oldLifespan;
|
Range<Long> oldLifespan = null;
|
||||||
Range<Long> newLifespan;
|
Range<Long> newLifespan = null;
|
||||||
try (LockHold hold = LockHold.lock(space.lock.writeLock())) {
|
try (LockHold hold = LockHold.lock(space.lock.writeLock())) {
|
||||||
if (!lifespan.contains(snap)) {
|
if (!lifespan.contains(snap)) {
|
||||||
throw new IllegalArgumentException("snap = " + snap);
|
throw new IllegalArgumentException("snap = " + snap);
|
||||||
}
|
}
|
||||||
if (flagsByte == computeFlagsByte(enabled, kinds)) {
|
if (flagsByte == computeFlagsByte(en, kinds)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
if (snap == getPlacedSnap()) {
|
if (snap == getPlacedSnap()) {
|
||||||
setEnabled(en);
|
this.doSetFlags(en, kinds);
|
||||||
return this;
|
that = this;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
that = doCopy();
|
||||||
|
that.doSetLifespan(DBTraceUtils.toRange(snap, getClearedSnap()));
|
||||||
|
that.doSetFlags(en, kinds);
|
||||||
|
oldLifespan = lifespan;
|
||||||
|
newLifespan = DBTraceUtils.toRange(getPlacedSnap(), snap - 1);
|
||||||
|
this.doSetLifespan(newLifespan);
|
||||||
}
|
}
|
||||||
|
|
||||||
that = doCopy();
|
|
||||||
that.doSetLifespan(DBTraceUtils.toRange(snap, getClearedSnap()));
|
|
||||||
that.doSetFlags(en, kinds);
|
|
||||||
oldLifespan = lifespan;
|
|
||||||
newLifespan = DBTraceUtils.toRange(getPlacedSnap(), snap - 1);
|
|
||||||
this.doSetLifespan(newLifespan);
|
|
||||||
}
|
}
|
||||||
// Yes, issue ADDED, before LIFESPAN_CHANGED, as noted in docs
|
if (that == this) {
|
||||||
space.trace.setChanged(
|
space.trace.setChanged(
|
||||||
new TraceChangeRecord<>(TraceBreakpointChangeType.ADDED, space, that));
|
new TraceChangeRecord<>(TraceBreakpointChangeType.CHANGED, space, this));
|
||||||
space.trace.setChanged(new TraceChangeRecord<>(TraceBreakpointChangeType.LIFESPAN_CHANGED,
|
}
|
||||||
space, this, oldLifespan, newLifespan));
|
else {
|
||||||
|
// Yes, issue ADDED, before LIFESPAN_CHANGED, as noted in docs
|
||||||
|
space.trace.setChanged(
|
||||||
|
new TraceChangeRecord<>(TraceBreakpointChangeType.ADDED, space, that));
|
||||||
|
space.trace.setChanged(
|
||||||
|
new TraceChangeRecord<>(TraceBreakpointChangeType.LIFESPAN_CHANGED,
|
||||||
|
space, this, Objects.requireNonNull(oldLifespan),
|
||||||
|
Objects.requireNonNull(newLifespan)));
|
||||||
|
}
|
||||||
return that;
|
return that;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,117 +15,252 @@
|
||||||
*/
|
*/
|
||||||
package ghidra.trace.database.breakpoint;
|
package ghidra.trace.database.breakpoint;
|
||||||
|
|
||||||
import static ghidra.lifecycle.Unfinished.TODO;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.junit.Ignore;
|
import java.util.Set;
|
||||||
import org.junit.Test;
|
|
||||||
|
import org.junit.*;
|
||||||
|
|
||||||
|
import com.google.common.collect.Range;
|
||||||
|
|
||||||
|
import ghidra.test.AbstractGhidraHeadlessIntegrationTest;
|
||||||
|
import ghidra.trace.database.ToyDBTraceBuilder;
|
||||||
|
import ghidra.trace.model.breakpoint.TraceBreakpoint;
|
||||||
|
import ghidra.trace.model.breakpoint.TraceBreakpointKind;
|
||||||
|
import ghidra.trace.model.thread.TraceThread;
|
||||||
|
import ghidra.util.database.UndoableTransaction;
|
||||||
|
import ghidra.util.exception.DuplicateNameException;
|
||||||
|
|
||||||
|
public class DBTraceBreakpointManagerTest extends AbstractGhidraHeadlessIntegrationTest {
|
||||||
|
|
||||||
|
ToyDBTraceBuilder b;
|
||||||
|
DBTraceBreakpointManager breakpointManager;
|
||||||
|
|
||||||
|
TraceThread thread;
|
||||||
|
TraceBreakpoint breakMain;
|
||||||
|
TraceBreakpoint breakVarA;
|
||||||
|
TraceBreakpoint breakVarB;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUpBreakpointManagerTest() throws Exception {
|
||||||
|
b = new ToyDBTraceBuilder("Testing", "Toy:BE:64:default");
|
||||||
|
breakpointManager = b.trace.getBreakpointManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDownBreakpointManagerTest() throws Exception {
|
||||||
|
b.close();
|
||||||
|
}
|
||||||
|
|
||||||
@Ignore("TODO")
|
|
||||||
public class DBTraceBreakpointManagerTest {
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddBreakpoint() throws Exception {
|
public void testAddBreakpoint() throws Exception {
|
||||||
TODO();
|
try (UndoableTransaction tid = b.startTransaction()) {
|
||||||
|
breakpointManager.addBreakpoint("Breaks[0]", Range.closed(0L, 10L), b.addr(0x00400000),
|
||||||
|
Set.of(), Set.of(TraceBreakpointKind.SW_EXECUTE), true, "main");
|
||||||
|
}
|
||||||
|
|
||||||
|
try (UndoableTransaction tid = b.startTransaction()) {
|
||||||
|
breakpointManager.addBreakpoint("Breaks[0]", Range.closed(0L, 10L),
|
||||||
|
b.range(0x00400000, 0x00400003), Set.of(), Set.of(), false, "duplicate");
|
||||||
|
}
|
||||||
|
catch (DuplicateNameException e) {
|
||||||
|
// pass
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(1, breakpointManager.getBreakpointsByPath("Breaks[0]").size());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addBreakpoints() throws Exception {
|
||||||
|
try (UndoableTransaction tid = b.startTransaction()) {
|
||||||
|
thread = b.getOrAddThread("Thread1", 0);
|
||||||
|
breakMain = breakpointManager.addBreakpoint("Breaks[0]", Range.closed(0L, 10L),
|
||||||
|
b.addr(0x00400000),
|
||||||
|
Set.of(), Set.of(TraceBreakpointKind.SW_EXECUTE), true, "main");
|
||||||
|
breakVarA = breakpointManager.addBreakpoint("Breaks[1]", Range.closed(0L, 10L),
|
||||||
|
b.range(0x00600010, 0x00600013),
|
||||||
|
Set.of(), Set.of(TraceBreakpointKind.WRITE), false, "varA");
|
||||||
|
breakVarB = breakpointManager.addBreakpoint("Breaks[1]", Range.closed(11L, 20L),
|
||||||
|
b.range(0x00600020, 0x00600023),
|
||||||
|
Set.of(thread), Set.of(TraceBreakpointKind.WRITE), false, "varB");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAllBreakpoints() throws Exception {
|
public void testGetAllBreakpoints() throws Exception {
|
||||||
TODO();
|
addBreakpoints();
|
||||||
|
assertEquals(Set.of(breakMain, breakVarA, breakVarB),
|
||||||
|
Set.copyOf(breakpointManager.getAllBreakpoints()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBreakpointsByPath() throws Exception {
|
public void testBreakpointsByPath() throws Exception {
|
||||||
TODO();
|
addBreakpoints();
|
||||||
|
assertEquals(Set.of(breakMain),
|
||||||
|
Set.copyOf(breakpointManager.getBreakpointsByPath("Breaks[0]")));
|
||||||
|
assertEquals(Set.of(breakVarA, breakVarB),
|
||||||
|
Set.copyOf(breakpointManager.getBreakpointsByPath("Breaks[1]")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBreakpointPlacedByPath() throws Exception {
|
||||||
|
addBreakpoints();
|
||||||
|
assertEquals(breakVarA, breakpointManager.getPlacedBreakpointByPath(0, "Breaks[1]"));
|
||||||
|
assertEquals(breakVarB, breakpointManager.getPlacedBreakpointByPath(11, "Breaks[1]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBreakpointsAt() throws Exception {
|
public void testBreakpointsAt() throws Exception {
|
||||||
TODO();
|
addBreakpoints();
|
||||||
|
assertEquals(Set.of(breakMain),
|
||||||
|
Set.copyOf(breakpointManager.getBreakpointsAt(0, b.addr(0x00400000))));
|
||||||
|
assertEquals(Set.of(breakVarA),
|
||||||
|
Set.copyOf(breakpointManager.getBreakpointsAt(0, b.addr(0x00600010))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBreakpointsIntersecting() throws Exception {
|
public void testBreakpointsIntersecting() throws Exception {
|
||||||
TODO();
|
addBreakpoints();
|
||||||
|
assertEquals(Set.of(breakMain, breakVarA),
|
||||||
|
Set.copyOf(breakpointManager.getBreakpointsIntersecting(Range.singleton(0L),
|
||||||
|
b.range(0x00400000, 0x00600010))));
|
||||||
|
assertEquals(Set.of(breakMain),
|
||||||
|
Set.copyOf(breakpointManager.getBreakpointsIntersecting(Range.singleton(0L),
|
||||||
|
b.range(0x00400000, 0x00400010))));
|
||||||
|
assertEquals(Set.of(breakVarA),
|
||||||
|
Set.copyOf(breakpointManager.getBreakpointsIntersecting(Range.singleton(0L),
|
||||||
|
b.range(0x00600000, 0x00600010))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetTrace() throws Exception {
|
public void testGetTrace() throws Exception {
|
||||||
TODO();
|
addBreakpoints();
|
||||||
|
assertEquals(b.trace, breakMain.getTrace());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPath() throws Exception {
|
public void testGetPath() throws Exception {
|
||||||
TODO();
|
addBreakpoints();
|
||||||
|
assertEquals("Breaks[0]", breakMain.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetName() throws Exception {
|
public void testSetGetName() throws Exception {
|
||||||
TODO();
|
addBreakpoints();
|
||||||
}
|
assertEquals("Breaks[0]", breakMain.getName());
|
||||||
|
try (UndoableTransaction tid = b.startTransaction()) {
|
||||||
@Test
|
breakMain.setName("bpt 0");
|
||||||
public void testGetName() throws Exception {
|
assertEquals("bpt 0", breakMain.getName());
|
||||||
TODO();
|
}
|
||||||
}
|
assertEquals("bpt 0", breakMain.getName());
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetRange() throws Exception {
|
|
||||||
TODO();
|
|
||||||
// include min,max address, length
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetLifespan() throws Exception {
|
|
||||||
TODO();
|
|
||||||
// include placed,cleared,
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSetCleared() throws Exception {
|
|
||||||
TODO();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSplit() throws Exception {
|
|
||||||
TODO();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSetEnabled() throws Exception {
|
|
||||||
TODO();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsEnabled() throws Exception {
|
|
||||||
TODO();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSplitWithEnabled() throws Exception {
|
|
||||||
TODO();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetKinds() throws Exception {
|
|
||||||
TODO();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetThreads() throws Exception {
|
public void testGetThreads() throws Exception {
|
||||||
TODO();
|
addBreakpoints();
|
||||||
|
assertEquals(Set.of(), Set.copyOf(breakMain.getThreads()));
|
||||||
|
assertEquals(Set.of(thread), Set.copyOf(breakVarB.getThreads()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetComment() throws Exception {
|
public void testGetRange() throws Exception {
|
||||||
TODO();
|
addBreakpoints();
|
||||||
|
assertEquals(b.addr(0x00400000), breakMain.getMinAddress());
|
||||||
|
assertEquals(b.addr(0x00400000), breakMain.getMaxAddress());
|
||||||
|
assertEquals(b.range(0x00400000, 0x00400000), breakMain.getRange());
|
||||||
|
assertEquals(1, breakMain.getLength());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetComment() throws Exception {
|
public void testGetLifespan() throws Exception {
|
||||||
TODO();
|
addBreakpoints();
|
||||||
|
assertEquals(0, breakMain.getPlacedSnap());
|
||||||
|
assertEquals(10, breakMain.getClearedSnap());
|
||||||
|
assertEquals(Range.closed(0L, 10L), breakMain.getLifespan());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetCleared() throws Exception {
|
||||||
|
addBreakpoints();
|
||||||
|
try (UndoableTransaction tid = b.startTransaction()) {
|
||||||
|
breakMain.setClearedSnap(5);
|
||||||
|
assertEquals(5, breakMain.getClearedSnap());
|
||||||
|
}
|
||||||
|
assertEquals(0, breakMain.getPlacedSnap());
|
||||||
|
assertEquals(5, breakMain.getClearedSnap());
|
||||||
|
assertEquals(Range.closed(0L, 5L), breakMain.getLifespan());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSplitAndSet() throws Exception {
|
||||||
|
addBreakpoints();
|
||||||
|
|
||||||
|
TraceBreakpoint disMain;
|
||||||
|
try (UndoableTransaction tid = b.startTransaction()) {
|
||||||
|
TraceBreakpoint oopsMain =
|
||||||
|
breakMain.splitAndSet(0, true, Set.of(TraceBreakpointKind.HW_EXECUTE));
|
||||||
|
assertSame(breakMain, oopsMain);
|
||||||
|
disMain =
|
||||||
|
breakMain.splitAndSet(6, false, Set.of(TraceBreakpointKind.HW_EXECUTE));
|
||||||
|
assertNotSame(breakMain, disMain);
|
||||||
|
TraceBreakpoint sameDis =
|
||||||
|
disMain.splitAndSet(8, false, Set.of(TraceBreakpointKind.HW_EXECUTE));
|
||||||
|
assertSame(disMain, sameDis);
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue(breakMain.isEnabled());
|
||||||
|
assertEquals(Set.of(TraceBreakpointKind.HW_EXECUTE), Set.copyOf(breakMain.getKinds()));
|
||||||
|
|
||||||
|
assertFalse(disMain.isEnabled());
|
||||||
|
assertEquals(Set.of(TraceBreakpointKind.HW_EXECUTE), Set.copyOf(disMain.getKinds()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetIsEnabled() throws Exception {
|
||||||
|
addBreakpoints();
|
||||||
|
assertTrue(breakMain.isEnabled());
|
||||||
|
try (UndoableTransaction tid = b.startTransaction()) {
|
||||||
|
breakMain.setEnabled(false);
|
||||||
|
assertFalse(breakMain.isEnabled());
|
||||||
|
}
|
||||||
|
assertFalse(breakMain.isEnabled());
|
||||||
|
try (UndoableTransaction tid = b.startTransaction()) {
|
||||||
|
breakMain.setEnabled(true);
|
||||||
|
assertTrue(breakMain.isEnabled());
|
||||||
|
}
|
||||||
|
assertTrue(breakMain.isEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetGetKinds() throws Exception {
|
||||||
|
addBreakpoints();
|
||||||
|
assertEquals(Set.of(TraceBreakpointKind.SW_EXECUTE), Set.copyOf(breakMain.getKinds()));
|
||||||
|
try (UndoableTransaction tid = b.startTransaction()) {
|
||||||
|
breakMain.setKinds(Set.of(TraceBreakpointKind.HW_EXECUTE));
|
||||||
|
assertEquals(Set.of(TraceBreakpointKind.HW_EXECUTE), Set.copyOf(breakMain.getKinds()));
|
||||||
|
}
|
||||||
|
assertEquals(Set.of(TraceBreakpointKind.HW_EXECUTE), Set.copyOf(breakMain.getKinds()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetGetComment() throws Exception {
|
||||||
|
addBreakpoints();
|
||||||
|
assertEquals("main", breakMain.getComment());
|
||||||
|
try (UndoableTransaction tid = b.startTransaction()) {
|
||||||
|
breakMain.setComment("WinMain");
|
||||||
|
assertEquals("WinMain", breakMain.getComment());
|
||||||
|
}
|
||||||
|
assertEquals("WinMain", breakMain.getComment());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDelete() throws Exception {
|
public void testDelete() throws Exception {
|
||||||
TODO();
|
addBreakpoints();
|
||||||
|
assertEquals(Set.of(breakMain),
|
||||||
|
Set.copyOf(breakpointManager.getBreakpointsByPath("Breaks[0]")));
|
||||||
|
try (UndoableTransaction tid = b.startTransaction()) {
|
||||||
|
breakMain.delete();
|
||||||
|
assertEquals(Set.of(), Set.copyOf(breakpointManager.getBreakpointsByPath("Breaks[0]")));
|
||||||
|
}
|
||||||
|
assertEquals(Set.of(), Set.copyOf(breakpointManager.getBreakpointsByPath("Breaks[0]")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue