@Test
	public void testSaveAndLoad() throws Exception {
		try (Transaction tx = b.startTransaction()) {
			b.addInstruction(0, b.addr(0x4004), b.host, b.buf(0xf4, 0));

			TraceThread thread = b.getOrAddThread("Thread 1", 0);
			DBTraceCodeSpace regCode = manager.getCodeRegisterSpace(thread, true);
			regCode.definedData()
					.create(Lifespan.nowOn(0), b.language.getRegister("r4"),
						LongDataType.dataType);
		}

		File file = b.save();
		try (@SuppressWarnings("hiding")
		ToyDBTraceBuilder b = new ToyDBTraceBuilder(file)) {
			@SuppressWarnings("hiding")
			DBTraceCodeManager manager = b.trace.getCodeManager();

			// No transaction, so it had better exist
			TraceThread thread = b.getOrAddThread("Thread 1", 0);
			List<TraceCodeUnit> units = new ArrayList<>();
			for (TraceCodeUnit u : manager.definedUnits().get(0, true)) {
				units.add(u);
			}
			// Again, no transaction, so that space had better exist
			for (TraceCodeUnit u : manager.getCodeRegisterSpace(thread, true)
					.definedUnits()
					.get(0,
						true)) {
				units.add(u);
			}

			assertEquals(2, units.size());

			assertTrue(units.get(0) instanceof TraceInstruction);
			TraceInstruction instruction = (TraceInstruction) units.get(0);
			assertEquals(b.addr(0x4004), instruction.getAddress());
			assertEquals("ret", instruction.getMnemonicString()); // Meh
			assertEquals(2, instruction.getLength());

			assertTrue(units.get(1) instanceof TraceData);
			TraceData data = (TraceData) units.get(1);
			assertEquals(b.language.getRegister("r4").getAddress(), data.getAddress());
			assertEquals(new Scalar(32, 0), data.getValue());
			assertEquals(4, data.getLength());
		}
	}
This test is interesting because the pointer type def causes an update to the data type
settings <em>while the unit is still being created</em>. This will invalidate the trace's
caches. All of them, including the defined data units, which can become the cause of many
timing issues.
Ghidra/Debug/Framework-TraceModeling/src/test/java/ghidra/trace/database/listing/DBTraceCodeManagerTest.java