mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
GP-4528: Fix byte values in trace diff view
This commit is contained in:
parent
6389d9630c
commit
e914b126db
5 changed files with 70 additions and 55 deletions
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
package ghidra.trace.database.program;
|
||||
|
||||
import static ghidra.lifecycle.Unfinished.*;
|
||||
import static ghidra.lifecycle.Unfinished.TODO;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -42,8 +42,8 @@ public class DBTraceProgramViewListingTest extends AbstractGhidraHeadlessIntegra
|
|||
|
||||
ToyDBTraceBuilder b;
|
||||
|
||||
DBTraceProgramView view;
|
||||
DBTraceProgramViewListing listing; // TODO: Do I want to expose the internal types?
|
||||
DBTraceVariableSnapProgramView view;
|
||||
DBTraceProgramViewListing listing;
|
||||
DBTraceMemoryManager memory;
|
||||
DBTraceCodeManager code;
|
||||
|
||||
|
@ -878,4 +878,22 @@ public class DBTraceProgramViewListingTest extends AbstractGhidraHeadlessIntegra
|
|||
assertEquals(i4005, listing.getDefinedCodeUnitBefore(b.addr(0x4006)));
|
||||
assertEquals(d4000, listing.getDefinedCodeUnitBefore(b.addr(0x4005)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCodeUnitsInTwoViews() throws Throwable {
|
||||
try (Transaction tx = b.startTransaction()) {
|
||||
memory.putBytes(0, b.addr(0x00400000), b.buf(1, 2, 3, 4, 5, 6, 7, 8));
|
||||
memory.putBytes(1, b.addr(0x00400000), b.buf(8, 7, 6, 5, 4, 3, 2, 1));
|
||||
}
|
||||
|
||||
view.setSnap(1);
|
||||
DBTraceProgramView view0 = b.trace.getFixedProgramView(0);
|
||||
DBTraceProgramViewListing listing0 = view0.getListing();
|
||||
|
||||
CodeUnit cu0 = listing0.getCodeUnitAt(b.addr(0x00400000));
|
||||
CodeUnit cu1 = listing.getCodeUnitAt(b.addr(0x00400000));
|
||||
|
||||
assertArrayEquals(b.arr(1), cu0.getBytes());
|
||||
assertArrayEquals(b.arr(8), cu1.getBytes());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,8 @@ import org.junit.*;
|
|||
|
||||
import db.Transaction;
|
||||
import ghidra.program.database.ProgramBuilder;
|
||||
import ghidra.program.model.address.*;
|
||||
import ghidra.program.model.address.AddressSet;
|
||||
import ghidra.program.model.address.AddressSpace;
|
||||
import ghidra.program.model.lang.LanguageNotFoundException;
|
||||
import ghidra.program.model.mem.MemoryBlock;
|
||||
import ghidra.test.AbstractGhidraHeadlessIntegrationTest;
|
||||
|
@ -31,50 +32,47 @@ import ghidra.trace.database.ToyDBTraceBuilder;
|
|||
import ghidra.trace.database.memory.DBTraceMemoryManager;
|
||||
import ghidra.trace.database.memory.DBTraceMemoryRegion;
|
||||
import ghidra.trace.model.memory.TraceMemoryFlag;
|
||||
import ghidra.trace.model.memory.TraceOverlappedRegionException;
|
||||
import ghidra.util.exception.DuplicateNameException;
|
||||
|
||||
public class DBTraceProgramViewMemoryTest extends AbstractGhidraHeadlessIntegrationTest {
|
||||
|
||||
ToyDBTraceBuilder b;
|
||||
ToyDBTraceBuilder tb;
|
||||
|
||||
DBTraceProgramView view;
|
||||
DBTraceVariableSnapProgramView view;
|
||||
DBTraceProgramViewMemory vmem;
|
||||
DBTraceMemoryManager memory;
|
||||
|
||||
@Before
|
||||
public void setUpTraceProgramViewMemoryTest() throws LanguageNotFoundException, IOException {
|
||||
b = new ToyDBTraceBuilder("Testing", ProgramBuilder._TOY64_BE);
|
||||
try (Transaction tx = b.startTransaction()) {
|
||||
b.trace.getTimeManager().createSnapshot("Created");
|
||||
tb = new ToyDBTraceBuilder("Testing", ProgramBuilder._TOY64_BE);
|
||||
try (Transaction tx = tb.startTransaction()) {
|
||||
tb.trace.getTimeManager().createSnapshot("Created");
|
||||
}
|
||||
memory = b.trace.getMemoryManager();
|
||||
memory = tb.trace.getMemoryManager();
|
||||
// NOTE: First snap has to exist first
|
||||
view = b.trace.getProgramView();
|
||||
view = tb.trace.getProgramView();
|
||||
vmem = view.getMemory();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDownTraceProgramViewListingTest() {
|
||||
if (b != null) {
|
||||
b.close();
|
||||
if (tb != null) {
|
||||
tb.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBlockInOverlay() throws DuplicateNameException, TraceOverlappedRegionException,
|
||||
AddressOutOfBoundsException {
|
||||
public void testBlockInOverlay() throws Throwable {
|
||||
AddressSpace os;
|
||||
DBTraceMemoryRegion io;
|
||||
try (Transaction tx = b.startTransaction()) {
|
||||
try (Transaction tx = tb.startTransaction()) {
|
||||
os = memory.createOverlayAddressSpace("test",
|
||||
b.trace.getBaseAddressFactory().getDefaultAddressSpace());
|
||||
io = (DBTraceMemoryRegion) memory.createRegion(".io", 0, b.range(os, 0x1000, 0x1fff),
|
||||
tb.trace.getBaseAddressFactory().getDefaultAddressSpace());
|
||||
io = (DBTraceMemoryRegion) memory.createRegion(".io", 0, tb.range(os, 0x1000, 0x1fff),
|
||||
TraceMemoryFlag.READ, TraceMemoryFlag.WRITE, TraceMemoryFlag.VOLATILE);
|
||||
}
|
||||
|
||||
AddressSet asSet = new AddressSet(vmem);
|
||||
assertEquals(b.set(b.range(os, 0x1000, 0x1fff)), asSet);
|
||||
assertEquals(tb.set(tb.range(os, 0x1000, 0x1fff)), asSet);
|
||||
|
||||
MemoryBlock[] blocks = vmem.getBlocks();
|
||||
assertEquals(1, blocks.length);
|
||||
|
@ -82,7 +80,26 @@ public class DBTraceProgramViewMemoryTest extends AbstractGhidraHeadlessIntegrat
|
|||
MemoryBlock blk = blocks[0];
|
||||
assertSame(blk, vmem.getRegionBlock(io));
|
||||
assertEquals(".io", blk.getName());
|
||||
assertEquals(b.addr(os, 0x1000), blk.getStart());
|
||||
assertEquals(b.addr(os, 0x1fff), blk.getEnd());
|
||||
assertEquals(tb.addr(os, 0x1000), blk.getStart());
|
||||
assertEquals(tb.addr(os, 0x1fff), blk.getEnd());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBytesInTwoViews() throws Throwable {
|
||||
try (Transaction tx = tb.startTransaction()) {
|
||||
memory.putBytes(0, tb.addr(0x00400000), tb.buf(1, 2, 3, 4, 5, 6, 7, 8));
|
||||
memory.putBytes(1, tb.addr(0x00400000), tb.buf(8, 7, 6, 5, 4, 3, 2, 1));
|
||||
}
|
||||
|
||||
view.setSnap(1);
|
||||
DBTraceProgramView view0 = tb.trace.getFixedProgramView(0);
|
||||
|
||||
byte[] actual = new byte[8];
|
||||
|
||||
view0.getMemory().getBytes(tb.addr(0x00400000), actual);
|
||||
assertArrayEquals(tb.arr(1, 2, 3, 4, 5, 6, 7, 8), actual);
|
||||
|
||||
view.getMemory().getBytes(tb.addr(0x00400000), actual);
|
||||
assertArrayEquals(tb.arr(8, 7, 6, 5, 4, 3, 2, 1), actual);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue