#501·doctest

msys2's mingw-w64-x86_64: attached gdb causes multithreaded test to crash on thread termination

Author: yeputonsCreated Apr 27, 2021Updated May 14, 2026
Labelstype/bughas-workaroundplatform/windows

Description

May be distantly related to #401

Steps to reproduce

  1. Install msys2 and pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-gdb
  2. Create a directory with the latest doctest.h (I've used both 2.4.6 and 2.4.1) and the following code in test.cpp:
cpp
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
#include <thread>

TEST_CASE("Test thread") {
    std::thread([&]() {
        CHECK(2 * 2 == 4);
    }).join();
}
  1. Compile it with g++ test.cpp -o test.exe (IIRC, no optimizations by default).
  2. Run test.exe, test with a single assertion passes.
  3. Now run gdb -ex run -ex where -ex "set confirm off" -ex q test.exe (same as running gdb test.exe and typing run, where, q and confirming)

Expected result: program runs, and the test with a single assertion passes. Actual result:

GNU gdb (GDB) 10.1
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-w64-mingw32".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from test.exe...
Starting program: F:\_0_MAIN\Teach\2020\cpp\drafts\210427\test.exe 
warning: [doctest] doctest version is "2.4.6"
[doctest] run with "--help" for options
[New Thread 11008.0x2070]
warning: Critical error detected c0000374

Thread 2 received signal SIGTRAP, Trace/breakpoint trap.
[Switching to Thread 11008.0x2070]
0x00000000774cf680 in ntdll!RtlUnhandledExceptionFilter ()
   from C:\Windows\SYSTEM32\ntdll.dll
#0  0x00000000774cf680 in ntdll!RtlUnhandledExceptionFilter ()
   from C:\Windows\SYSTEM32\ntdll.dll
#1  0x00000000774cfc86 in ntdll!EtwEnumerateProcessRegGuids ()
   from C:\Windows\SYSTEM32\ntdll.dll
#2  0x00000000774d08a2 in ntdll!RtlQueryProcessLockInformation ()
   from C:\Windows\SYSTEM32\ntdll.dll
#3  0x00000000774d29b4 in ntdll!RtlLogStackBackTrace ()
   from C:\Windows\SYSTEM32\ntdll.dll
#4  0x000000007743a0b0 in ntdll!RtlFreeHeap ()
   from C:\Windows\SYSTEM32\ntdll.dll
#5  0x000007feff0310c8 in msvcrt!free () from C:\Windows\system32\msvcrt.dll
#6  0x000007fecca29827 in ?? ()
   from C:\Software\msys64\mingw64\bin\libstdc++-6.dll
#7  0x000000013fc299a6 in run_dtor_list (ptr=<synthetic pointer>)
    at C:/_/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/tls_atexit.c:59
#8  tls_callback (hDllHandle=<optimized out>, dwReason=<optimized out>, 
    lpReserved=<optimized out>)
    at C:/_/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/tls_atexit.c:155
#9  0x0000000077455088 in ntdll!RtlpUnWaitCriticalSection ()
   from C:\Windows\SYSTEM32\ntdll.dll
#10 0x000000007744868f in ntdll!LdrShutdownThread ()
   from C:\Windows\SYSTEM32\ntdll.dll
#11 0x0000000077453ee8 in ntdll!RtlExitUserThread ()
   from C:\Windows\SYSTEM32\ntdll.dll
#12 0x000007feff034213 in msvcrt!_endthreadex ()
   from C:\Windows\system32\msvcrt.dll
#13 0x000007fef1394f6e in ?? ()
   from C:\Software\msys64\mingw64\bin\libwinpthread-1.dll
#14 0x000007feff03415f in srand () from C:\Windows\system32\msvcrt.dll
#15 0x000007feff036ebd in msvcrt!_ftime64_s ()
   from C:\Windows\system32\msvcrt.dll
#16 0x00000000772059cd in KERNEL32!BaseThreadInitThunk ()
   from C:\Windows\system32\kernel32.dll
#17 0x000000007746383d in ntdll!RtlUserThreadStart ()
   from C:\Windows\SYSTEM32\ntdll.dll
#18 0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

How to make the issue go away

  • Comment out CHECK inside the second thread.

Extra information

  • doctest version: v2.4.6
  • Operating System: Windows 7 Pro x64 En
  • Compiler+version: g++ (Rev10, Built by MSYS2 project) 10.2.0 (64-bit)