7.4 Walking the Call Chain

During the course of program execution, it is sometimes necessary to navigate the call chain. Frame-based exception handling is one case where this is done. Call chain navigation is only possible in the reverse direction (latest to earliest or top to bottom procedure).

The steps to perform for call chain navigation are:

  1. Build an invocation context block when given a program state (which contains a register set).

    For the current routine, an initial invocation context block can be obtained by calling RtlCaptureContext().

  2. Repeatedly call RtlVirtualUnwind() and RtlLookupFunctionEntry() until the end of the chain (ControlPc== 0) has been reached.

Compilers are allowed to optimize high-level language procedure calls in such a way that they do not appear in the invocation chain. For example, inline procedures never appear in the invocation chain.

No assumptions should be made about the relative positions of any memory used for procedure frame information. There is no guarantee that successive stack frames will always appear at higher addresses.