Debugging Tools for Windows
k, kb, kd, kp, kP, kv (Display Stack Backtrace)
The k* commands display the stack frame of the given thread, together with related information..
Syntax
User-Mode
[~Thread] k[b|p|P|v] [n] [f] [L] [FrameCount]
[~Thread] k[b|p|P|v] [n] [f] [L] = BasePtr [FrameCount]
[~Thread] k[b|p|P|v] [n] [f] [L] = BasePtr StackPtr InstructionPtr
[~Thread] kd [WordCount]
Kernel-Mode
[Processor] k[b|p|P|v] [n] [f] [L] [FrameCount]
[Processor] k[b|p|P|v] [n] [f] [L] = BasePtr [FrameCount]
[Processor] k[b|p|P|v] [n] [f] [L] = BasePtr StackPtr InstructionPtr
[Processor] kd [WordCount]
Parameters
- Thread
- Specifies the thread whose stack is to be displayed. If you omit this parameter, the stack of the current thread is displayed. For more information about thread syntax, see Thread Syntax. You can specify threads only in user mode.
- Processor
- Specifies the processor whose stack is to be displayed. For more information about processor syntax, see Multiprocessor Syntax. You can specify processors only in kernel mode.
- b
- Displays the first three parameters that are passed to each function in the stack trace.
- p
- Displays all of the parameters for each function that is called in the stack trace. The parameter list includes each parameter's data type, name, and value. The p option is case sensitive. This parameter requires full symbol information.
- P
- Displays all of the parameters for each function that is called in the stack trace, like the p parameter. However, for P, the function parameters are printed on a second line of the display, instead of on the same line as the rest of the data.
- v
- Displays frame pointer omission (FPO) information. On x86-based processors, the display also includes calling convention information.
- n
- Displays frame numbers.
- f
- Displays the distance between adjacent frames. This distance is the number of bytes that separate the frames on the actual stack.
- L
- Hides source lines in the display. L is case sensitive.
- FrameCount
- Specifies the number of stack frames to display. You should specify this number in hexadecimal format, unless you have changed the radix by using the n (Set Number Base) command. The default value is 20 (0x14), unless you have changed the default value by using the .kframes (Set Stack Length) command.
- BasePtr
- Specifies the base pointer for the stack trace. The BasePtr parameter is available only if there is an equal sign (=) after the command. On an x86-based processor, you can add one more parameter after BasePtr (which is interpreted as the FrameCount parameter) or two more parameters after BasePtr (which are interpreted as the StackPtr and InstructionPtr parameters).
- StackPtr
- (x86-based processor only) Specifies the stack pointer for the stack trace. If you omit StackPtr and InstructionPtr, the command uses the stack pointer that the esp register specifies and the instruction pointer that the eip register specifies.
- InstructionPtr
- (x86-based processor only) Specifies the instruction pointer for the stack trace. If you omit StackPtr and InstructionPtr, the command uses the stack pointer that the esp register specifies and the instruction pointer that the eip register specifies.
- WordCount
- Specifies the number of DWORD_PTR values in the stack to dump. The default value is 20 (0x14), unless you changed the default value by using the .kframes (Set Stack Length) command.
Environment
| Modes | User mode, kernel mode |
| Targets | Live, crash dump |
| Platforms | All |
Comments
When you issue the k, kb, kp, kP, or kv command, a stack trace is displayed in a tabular format. If line loading is enabled, source modules and line numbers are also displayed.
The stack trace includes the base pointer for the stack frame, the return address, and function names.
If you use the kp or kP command, the full parameters for each function that is called in the stack trace are displayed. The parameter list includes each parameter's data type, name, and value.
This command might be slow. For example, when MyFunction1 calls MyFunction2, the debugger must have full symbol information for MyFunction1 to display the parameters that are passed in this call. This command does not fully display internal Microsoft Windows routines that are not exposed in public symbols.
If you use the kb or kv command, the first three parameters that are passed to each function are displayed. If you use the kv command, FPO data is also displayed.
On an x86-based processor, the kv command also displays calling convention information.
On an Itanium-based processor, the kv command also causes nonvolatile registers to be displayed. This information enables you to trace the register stack.
When you use the kv command, the FPO information is added at the end of the line in the following format.
| FPO text | Meaning |
FPO: [non-Fpo]
| No FPO data for the frame. |
FPO: [N1,N2,N3]
| N1 is the total number of parameters.
N2 is the number of DWORD values for the local variables.
N3 is the number of registers that are saved.
|
FPO: [N1,N2] TrapFrame @ Address
| N1 is the total number of parameters.
N2 is the number of DWORD values for the locals.
Address is the address of the trap frame.
|
FPO: TaskGate Segment:0
| Segment is the segment selector for the task gate. |
FPO: [EBP 0xBase]
| Base is the base pointer for the frame. |
The kd command displays the raw stack data. Each DWORD value is displayed on a separate line. Symbol information is displayed for those lines together with associated symbols. This format creates a more detailed list than the other k* commands. The kd command is equivalent to a dds (Display Memory) command that uses the stack address as its parameter.
If you want a stack trace that begins somewhere other than the current stack location, you can use the BasePtr parameter to specify the base pointer value. If you are specifying the base pointer value on an x86-based processor, you should specify BasePtr, StackPtr, and InstructionPtr. These parameters should be the values of ebp, esp, and eip that correspond to the stack trace that you want. If you specify BasePtr and omit StackPtr and InstructionPtr, you might receive incorrect results if there are FPO frames present.
If you use the k command at the beginning of a function (before the function prolog has been executed), you receive incorrect results. The debugger uses the frame register to compute the current backtrace, and this register is not set correctly for a function until its prolog has been executed.
In user mode, the stack trace is based on the stack of the current thread. For more information about threads, see Controlling Processes and Threads.
In kernel mode, the stack trace is based on the current register context. You can set the register context to match a specific thread, context record, or trap frame.
Additional Information
For more information about stack traces and other ways to display stack traces, see Viewing the Call Stack. For more information about the register context and other context settings, see Changing Contexts.
Build machine: CAPEBUILD