public TraceThread initTrace(ToyDBTraceBuilder tb, AddressRange text, AddressRange stack,
			String stateInit, List<String> assembly) throws Throwable {
		TraceMemoryManager mm = tb.trace.getMemoryManager();
		TraceThread thread;
		try (Transaction tx = tb.startTransaction()) {
			thread = tb.getOrAddThread("Thread1", 0);
			mm.addRegion("Regions[bin:.text]", Lifespan.nowOn(0), text,
				TraceMemoryFlag.READ, TraceMemoryFlag.EXECUTE);
			mm.addRegion("Regions[stack1]", Lifespan.nowOn(0), stack,
				TraceMemoryFlag.READ, TraceMemoryFlag.WRITE);
			Assembler asm = Assemblers.getAssembler(tb.trace.getFixedProgramView(0));
			Iterator<Instruction> block = assembly.isEmpty() ? Collections.emptyIterator()
					: asm.assemble(text.getMinAddress(), assembly.toArray(String[]::new));
			Instruction last = null;
			while (block.hasNext()) {
				last = block.next();
			}
			Msg.info(this, "Assembly ended at: " + (last == null ? "null" : last.getMaxAddress()));
			if (!stateInit.isEmpty()) {
				PcodeExecutor<byte[]> exec =
					TraceSleighUtils.buildByteExecutor(tb.trace, 0, thread, 0);
				PcodeProgram initProg = SleighProgramCompiler.compileProgram(
					(SleighLanguage) tb.language, "test", stateInit,
					PcodeUseropLibrary.nil());
				exec.execute(initProg, PcodeUseropLibrary.nil());
			}
		}
		return thread;
	}
Build a trace with a program ready for emulation

<p>
This creates a relatively bare-bones trace with initial state for testing trace
emulation/interpolation. It adds ".text" and "stack" regions, creates a thread, assembles
given instructions, and then executes the given Sleigh source (in the context of the new
thread) to finish initializing the trace. Note, though given first, the Sleigh is executed
after assembly. Thus, it can be used to modify the resulting machine code by modifying the
memory where it was assembled.

@param tb the trace builder
@param stateInit Sleigh source to execute to initialize the trace state before emulation
@param assembly lines of assembly to place starting at {@code 0x00400000}
@return a new trace thread, whose register state is initialized as specified
@throws Throwable if anything goes wrong
Ghidra/Debug/Framework-TraceModeling/src/test/java/ghidra/pcode/exec/trace/AbstractTracePcodeEmulatorTest.java