Using Script Files

A script file is a text file that contains a sequence of debugger commands. There are a variety of ways for the debugger to load a script file and execute it. A script file can contain commands to be executed sequentially or can use a more complex flow of execution.

To execute a script file, you can do one of the following:

  • (KD and CDB only; only when the debugger starts) Create a script file that is named Ntsd.ini and put it in the directory where you are starting the debugger from. The debugger automatically executes this file when the debugger starts. To use a different file for the startup script file, specify the path and file name by using the -cf command-line option or by using the IniFile entry in the Tools.ini file.

  • (KD and CDB only; when each session starts) Create a script file and specify its path and file name by using the -cfr command-line option. The debugger automatically executes this script file when the debugger starts and every time that the target is restarted.

  • Use the $<, $><, $$<, and $$>< commands to execute a script file after the debugger is running. For more information about the syntax, see $<, $><, $><, $$>< (Run Script File).

The $>< and $$>< commands differ from the other methods of running scripts in one important way. When you use these commands, the debugger opens the specified script file, replaces all carriage returns with semicolons, and executes the resulting text as a single command block. These commands are useful for running scripts that contain debugger command programs. For more information about these programs, see Using Debugger Command Programs.X

You cannot use commands that are available only in WinDbg (such as .lsrcfix (Use Local Source Server), .lsrcpath (Set Local Source Path), .open (Open Source File), and .write_cmd_hist (Write Command History)) in script files, even if the script file is executed in WinDbg. In addition, you cannot use the .beep (Speaker Beep), .cls (Clear Screen), .hh (Open HTML Help File), .idle_cmd (Set Idle Command), .remote (Create Remote.exe Server), kernel-mode .restart (Restart Kernel Connection), user-mode .restart (Restart Target Application), or .wtitle (Set Window Title) commands in a script file.

WinDbg supports the same scripts as KD and CDB, with one minor exception. You can use the .remote_exit (Exit Debugging Client) command only in a script file that KD or CDB uses. You cannot exit from a debugging client though a script that is executed in WinDbg.