1

I am debugging a windows process that crashes if the execution stops for even a few milliseconds. (I don't know how many exactly, but it is definitely less than the time taken by my reflexes to resume the process.)

I know I can launch a windbg session via the command prompt by typing in windbg -p PID which brings up the GUI. But can I then further pass it windbg commands via the command prompt, such as bm *foo!bar* ".frame;gc";g".

Because If I can pass it these commands I can write these down in a .bat file and just run it. There would at least be no delay due to entering (or even copy-pasting) the commands.

tmj
  • 1,750
  • 2
  • 19
  • 34

1 Answers1

6

Use the -c parameter to pass them:

windbg -p PID -c "bm *foo!bar* .frame;gc;g"

According to the help (found by running windbg /?):

-c "command"

Specifies the initial debugger command to run at start-up. This command must be enclosed in quotation marks. Multiple commands can be separated with semicolons. (If you have a long command list, it may be easier to put them in a script and then use the -c option with the $<, $><, $><, $$>< (Run Script File) command.)

If you are starting a debugging client, this command must be intended for the debugging server. Client-specific commands, such as .lsrcpath, are not allowed.

You may need to play around with the quotes...

Edit: Based on this answer, you might be better off putting the commands into a script file to deal with the quotes:

script.txt (I think this is what you want):

bm *foo!bar* ".frame;gc"
g

Then in your batch file:

windbg -p PID -c "$<full_path_to_script_txt"
Community
  • 1
  • 1
Patrick Quirk
  • 23,334
  • 2
  • 57
  • 88