title: windbg command line to capture child process and make a breakpoint
body: <p>recently I have to debug an app with windbg, after reading <a href="http://msdn.microsoft.com/en-us/library/windows/hardware/ff561306%28v=vs.85%29.aspx" rel="nofollow">WinDbg Command-Line Options</a>, I found some solutions for either problem, but none could solve all these problems in a single run.</p>
  
  <p>Ganerally, I use <strong>-c</strong> option to make breakpoint on startup, use <strong>-logo</strong> option to output logging content to a static file, use <strong>-pn</strong> option to launch my app, so initially I have my command like this:</p>
  
  <pre><code>windbg -pn myapp.exe -logo "log.txt" -c 'bp WININET!InternetSetCookieExW "r; dv; kb; .dump /mu cookiedbg.dmp; g"'
  </code></pre>
  
  <p>This command would start <strong>myapp.exe</strong>, create a breakpoint at <strong>WININET!InternetSetCookieExW</strong> WIN32 API, when this breakpoint is hit, it dumps info to <strong>log.txt</strong> and then continue (by <strong>g</strong> command).</p>
  
  <p>However, I still have some problems unsolved, below lists my actual requirements:</p>
  
  <ol>
  <li>Since my app would create child process, windbg should be able to debug the main process and all child processes</li>
  <li><strong>Everything should be automated</strong>, so windbg should make a breakpoint at my app's startup, logging some infomation on breakpoint</li>
  </ol>
  
  <p>For the <strong>1st</strong> point, I found the <strong>-o</strong> option debugs all childprocess, so <code>windbg -pn myapp.exe -o</code> seems work></p>
  
  <p>But unfortunately, when an <strong>-o</strong> option is give, everytime a child process is forked, windbg hits a breakpoint, I have to manually use <strong>g</strong> command to continue, and this is not automated.</p>
  
  <p>For this, I then found <strong>-g</strong> option, which will ignore the initial breakpoint, but it still raise a critical probelm.</p>
  
  <p>The problem is, when <strong>-g</strong> option is specified, the commands provided by <strong>-c</strong> option could not be executed immediately after my app launches, since the initial breakpoint is ignored, I have to raise a breakpoint manually, then my commands could be executed on that hit.</p>
  
  <p>I tried <strong>-e</strong> option to raise some event for break, but got no result.</p>
  
  <p>To sum up, I use <strong>-o</strong> and <strong>-g</strong> options to make windbg catch all childprocesses and do not hit the initial breakpoint when a process is created, but then I couldn't inject commands via <strong>-c</strong> option.</p>
  
  <p>Thanks if someone could help to give the correct combination of commandline options.</p>