title: Invoke `cdb.exe` (windbg) to run noninteractively, and produce backtrace in case of crash?
body: <p>I have a C++ project which I use with travis-ci. Right now, I build it using boost.build, and on travis, when I run the unit tests, I do it through <code>gdb</code>, so that I get a backtrace in the event of a crash.</p>
  
  <p>To make <code>gdb</code> do this noninteractively, I invoke it like this on command-line:</p>
  
  <pre><code>gdb -return-child-result -batch -ex "run" -ex "thread apply all bt" -ex "quit" --args ./${file}
  </code></pre>
  
  <p>where <code>${file}</code> is my executable.</p>
  
  <p>This tells it to:</p>
  
  <ul>
  <li>start the process</li>
  <li>apply <code>bt</code> to all threads, which emits a backtrace in event of crash and also does nothing if there was no crash.</li>
  <li>finally it causes <code>gdb</code> to quit, and exit with the child's exit code.</li>
  </ul>
  
  <hr>
  
  <p>Now I would like to do the same thing on appveyor.</p>
  
  <p>Boost build seems to work perfectly out of the box in the appveyor VM, so hats off to them.</p>
  
  <p>However, I'm struggling to figure out how to configure <code>cdb</code>, the console cousin of <code>windbg</code>. It seems to hang in my build logs. Most of the examples I find online have to do with inspecting minidump files, not starting a process and debugging it as it runs.</p>
  
  <p>I'm currently invoking <code>cdb</code> like this (from appveyor powershell script):</p>
  
  <pre><code>cdb -c "$$&gt;&lt;cdb_script.txt" -o $file.fullName
  </code></pre>
  
  <p>And my <code>cdb_script.txt</code> looks like</p>
  
  <pre><code>.sympath srv*C:\Windows\Symbols*http://msdl.microsoft.com/download/symbols;
  .reload;
  ~* k 99;
  q
  </code></pre>
  
  <p>I'm basically cobbling this together from various things I googled, including</p>
  
  <ul>
  <li><a href="https://msdn.microsoft.com/en-us/library/windows/hardware/ff560096(v=vs.85).aspx" rel="noreferrer">https://msdn.microsoft.com/en-us/library/windows/hardware/ff560096(v=vs.85).aspx</a></li>
  <li><a href="http://www.sandboxie.com/index.php?HowToUseWinDbg" rel="noreferrer">http://www.sandboxie.com/index.php?HowToUseWinDbg</a></li>
  </ul>
  
  <p>I really hoped to find better docu or examples about how to do this specifically.</p>
  
  <p>The error I get right now is:</p>
  
  <pre><code>Microsoft (R) Windows Debugger Version 6.2.9200.20512 X86
  Copyright (c) Microsoft Corporation. All rights reserved.
  CommandLine: C:\projects\primer\test\stage\api.exe
  Symbol search path is: *** Invalid ***
  ****************************************************************************
  * Symbol loading may be unreliable without a symbol search path.           *
  * Use .symfix to have the debugger choose a symbol path.                   *
  * After setting your symbol path, use .reload to refresh symbol locations. *
  ****************************************************************************
  Executable search path is: 
  ModLoad: 009a0000 00a27000   api.exe 
  ModLoad: 76fb0000 7711f000   ntdll.dll
  ModLoad: 76520000 76660000   C:\windows\SysWOW64\KERNEL32.DLL
  ModLoad: 75fb0000 76087000   C:\windows\SysWOW64\KERNELBASE.dll
  ModLoad: 74350000 743f0000   C:\windows\SysWOW64\apphelp.dll
  SHIMVIEW: ShimInfo(Complete)
  ModLoad: 73b20000 73bd9000   C:\windows\SysWOW64\MSVCP140D.dll
  ModLoad: 741b0000 741cc000   C:\windows\SysWOW64\VCRUNTIME140D.dll
  ModLoad: 71bd0000 71d46000   C:\windows\SysWOW64\ucrtbased.dll
  (294.49c): Break instruction exception - code 80000003 (first chance)
  *** ERROR: Symbol file could not be found.  Defaulted to export symbols for ntdll.dll - 
  eax=00000000 ebx=00000000 ecx=19a00000 edx=00000000 esi=7ecdf000 edi=00000000
  eip=77063c7d esp=0110f8d4 ebp=0110f900 iopl=0         nv up ei pl zr na pe nc
  cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00000246
  ntdll!LdrInitShimEngineDynamic+0x6dd:
  77063c7d cc              int     3
  0:000&gt; cdb: Reading initial command '&gt;&lt;cdb_script.txt'
         ^ Syntax error in '&gt;&lt;cdb_script.txt'
  </code></pre>
  
  <p>Some variations I tried: </p>
  
  <ul>
  <li>Using <code>$$&lt;cdb_script.txt</code> instead of <code>$$&gt;&lt;cdb_script.txt</code>.</li>
  <li>Putting a semicolon after the last command in the script file</li>
  </ul>
  
  <hr>
  
  <p>Edit: I found also <a href="https://stackoverflow.com/questions/27954835/running-windbg-in-headless-mode?rq=1">this answer</a>, which explains again how to do it with minidumps but shows the script file in more detail.</p>
  
  <p>I don't really know what a minidump is tbh so <code>-o</code> option sounds more attractive, at least, more like <code>gdb</code>. But maybe I will end up trying to do it with minidumps if I can't figure this out.</p>