Refactor tracing init/exit

Refactor the init/exit tracing code to move more tracing internals out
of the main interpreter and into trace.c.