The present invention provides a method and system for capturing the call
stack of a currently-running thread at the time a profiler interrupt
occurs. The thread context of the thread is determined before a full push
of the thread context is performed by the CPU architecture. The hardware
state at the time of the interrupt is used to aid in determining which
portions of memory to search for portions of the thread context. Based on
the hardware state and the software state of the thread at the time of
the interrupt the thread context is captured. Code may also be injected
into a thread to capture a thread's call stack. The state of the thread
is altered to induce the thread to invoke the kernel's call stack API
itself, using its own context.