Add a pending_event state stack and use that when storing trace data.

This is a small step towards a "real" stack of states: the state stack
here is redundant with |ctx->event|.

On the road to #293.