Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoke `cdb.exe` (windbg) to run noninteractively, and produce backtrace in case of crash?

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 gdb, so that I get a backtrace in the event of a crash.

To make gdb do this noninteractively, I invoke it like this on command-line:

gdb -return-child-result -batch -ex "run" -ex "thread apply all bt" -ex "quit" --args ./${file}

where ${file} is my executable.

This tells it to:

  • start the process
  • apply bt to all threads, which emits a backtrace in event of crash and also does nothing if there was no crash.
  • finally it causes gdb to quit, and exit with the child's exit code.

Now I would like to do the same thing on appveyor.

Boost build seems to work perfectly out of the box in the appveyor VM, so hats off to them.

However, I'm struggling to figure out how to configure cdb, the console cousin of windbg. 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.

I'm currently invoking cdb like this (from appveyor powershell script):

cdb -c "$$><cdb_script.txt" -o $file.fullName

And my cdb_script.txt looks like

.sympath srv*C:\Windows\Symbols*http://msdl.microsoft.com/download/symbols;
.reload;
~* k 99;
q

I'm basically cobbling this together from various things I googled, including

  • https://msdn.microsoft.com/en-us/library/windows/hardware/ff560096(v=vs.85).aspx
  • http://www.sandboxie.com/index.php?HowToUseWinDbg

I really hoped to find better docu or examples about how to do this specifically.

The error I get right now is:

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> cdb: Reading initial command '><cdb_script.txt'
       ^ Syntax error in '><cdb_script.txt'

Some variations I tried:

  • Using $$<cdb_script.txt instead of $$><cdb_script.txt.
  • Putting a semicolon after the last command in the script file

Edit: I found also this answer, which explains again how to do it with minidumps but shows the script file in more detail.

I don't really know what a minidump is tbh so -o option sounds more attractive, at least, more like gdb. But maybe I will end up trying to do it with minidumps if I can't figure this out.

like image 586
Chris Beck Avatar asked Nov 17 '16 07:11

Chris Beck


1 Answers

Powershell variables use $ like in $file.fullName. This also seems to destroy the $$ in $$><.

You can escape that by a backtick, like

`$`$><cdb_script.txt

The following worked for me:

PS C:\Users\thomas.weller> & "C:\Program Files (x86)\Windows Kits\8.0\Debuggers\x86\cdb.exe" -c "`$`$><c:\cdb_script.txt" -o notepad.exe
[...]
0:000> cdb: Reading initial command '$$><c:\cdb_script.txt'
Yay!
0:000>
like image 156
Thomas Weller Avatar answered Oct 21 '22 01:10

Thomas Weller