K (Stack Trace)

Syntax

K

Description

The Stack Trace (K) command displays functions that have been called during program execution, including their arguments in the Command window. It also displays the address of the instruction that will be executed when control returns to each function.

Output from the Stack Trace command gives you the following information:

Functions listed in the reverse order in which they were called.

Arguments to each function, listed in parentheses.

The address or line number of the next instruction to be executed when control returns to that function.

Thus, the current function is listed first, and the address of the next instruction to be executed is the current CS:IP address. At the bottom is the main function of your program and the address of the next instruction to be executed when execution returns to the main function.

For each function, the command shows argument values in the current radix in parentheses after the function name.

You can use the address displayed for each line of the stack trace as an argument to the View Source (VS) or Unassemble (U) commands to see the code at the point where each function is called.

Mouse and Keyboard

In addition to typing the (K) command, you can use the Calls menu to see the stack trace.

Remarks

The term “stack trace” is used because as each function is called, its address and arguments are stored on or pushed onto the program stack. CodeView traces through the program stack to find out which functions were called. With C programs, the function main is always at the bottom of the stack.

The Stack Trace (K) command does not display anything until the program executes the beginning of the main function. The main function sets up the stack trace through frame pointers (the BP register), which CodeView uses to locate parameters, local variables, and return addresses.

If the main module is written in assembly language, the program must execute at least to the beginning of the first procedure called. In addition, your procedures must follow the standard Microsoft calling conventions.

Example

The following example shows the functions executed in a program so far, where hexadecimal is the current radix under CodeView:

>K

convert(0x3:0x17FC,1,2) address 1:ada

make_header(0x3:0x17FC) address 1:314

main(4,0x3:0x181E) address 1:c98

>

Here, convert is the currently executing function, at address ADA. It is passed three parameters: a pointer and two integers. When it returns control to make_header, the program is executing at address 314. When make_header returns, the program is executing at address C98.