GFlags - command lines

6.4k Views Asked by At

I want to start a process that takes a commandline. Using gflags I want to enable page heap and allow windbg to attach to the process each time it starts.

How can I add the commandline parameter in the gflags UI?

1

There are 1 best solutions below

0
On BEST ANSWER

You don't. And you're mixing up pretty unrelated things.

PageHeap

To enable the heap verification ("PageHeap") you set the configuration you want using the GFlags utility, either using the GUI or passing it the approporiate command-line arguments (See GFlags and PageHeap). Either way, this setting it global for all binaries with the name you define.

Debugging

To run the program under the debugger each and every time it starts you'd probably want to use the Debugger setting under Image File Execution Options. You can set it too using GFlags. Tick the Debugger checkbox in the Image File tab (after specifying the EXE name and hitting tab) and enter the path to the debugger.

The way this mechanism works is that (somewhere) inside CreateProcess there's a test whether or not IFEO\Debugger is set for the program you're trying to run, and if it is set, whatever set in the Debugger value is executed **and it is passed the original command line*.

So if you set

HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\foo.exe\Debugger

to be C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\windbg.exe and then try to execute C:\Users\d_blk\Desktop\foo.exe -param 1 -param 2, Windows runs

C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\windbg.exe C:\Users\d_blk\Desktop\foo.exe -param 1 -param 2

and WinDbg passes everything after foo.exe to the target program (as noted here).

So you see, there's no need to set the command-line arguments to the program you're debugging anywhere but wherever you're running it.

The only connection between PageHeap and IFEO\Debugger is that you can control both of them through the GFlags utility.

Caveats

Note all the usual caveats for using IFEO\Debugger. For example:

  • The caller gets from CreateProcess a handle to WinDbg, not the target process (and process ID, etc.).
  • Any information in a non-default STARTUPINFO argument applies to WinDbg, not the target process. Same for lpEnvironment I guess.

If that doesn't affect you great. If it does, an alternative might be adding an unhandled exception at the beginning of your program, and setting WinDbg as the post-mortem debugger (AeDebug)