Search code examples
windowswindbggitlab-cistack-tracewindows-error-reporting

Windows : Print stacktrace in case of a coredump during CI testing


I have set up a part of the Gitlab-CI continuous integration system of my company. We run builds and tests on all platforms nightly. I managed to print the stacktrace in case of a crashing process for Linux and MacOS (with GDB and LLDB respectively). I'm trying to do it aswell for Windows but i didn't find yet how to...

Coredump generation

I first tried to enable Windows Error Reporting, as said in the documentation. It works with the default settings, but I would prefer the coredumps to be generated in the executable directory...

I tried putting "%CD%" in the DumpFolder key (type REG_EXPAND_SZ, I checked), but it doesn't work... I'm now trying to understand how to generate the coredump with WinDbg instead, but I still can't figure out how yet.

Stacktrace display

When the coredump will be generated in the right folder, I will need to figure out how to print the stacktrace... Do you already know a command for this (this is mandatory for me) ?

Both powershell scripts or basic commands should be ok.

edit :

I could print the stacktrace of the generated coredump with windbg quite easily in local. However, for some reason, when the job is trigerred by Gitlab-CI, the coredump isn't generated... Is there any undocumented value to add to the Windows Error Reporting keys to generate the coredumps even if the faulty program is launched via Gitlab-CI ? (it works if I launch it via SSH)


Solution

  • I doubt that %CD% will work in this case. %CD% will likely expand to the current directory of the process which is reading the registry entry. That's not the same directory as your executable's directory.

    Have a look at ProcDump. The -x command line option lets you specify a directory where to put crash dump files.

    Here's what works for me:

    ..\procdump.exe  -e -x . SimpleCppCrash.exe -arg1 -arg2 -arg3
    

    I can verify that in the crash dump:

    0:000> !peb
    [...]
    CommandLine:  '"SimpleCppCrash.exe"  -arg1 -arg2 -arg3'
    [...]
    

    so, the executable has the arguments passed.

    The rest was already answered by @blabb: use cdb -c "<whatever>;q", potentially with -logo <logfile> option if you want it persistent.

    It is certainly possible with WinDbg/cdb alone, but I would not recommend it. If the exception needs to be examined in more detail, it's good to have the crash dump file still around.