Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When, on Windows 7, I launch a console program that should crash, I have the following cases:

  • If I double-click on it, it crashes and a "your program crashed" dialog popup opens up
  • If I launch it through a DOS console, it crashes and a "your program crashed" dialog popup opens up
  • If I launch it through a Cygwin console, it crashes silently. No dialog popup

Note that on Windows XP, everything works as expected (a dialog popup opens...), and I can debug the crashed program.

Is that a cygwin bug on Windows 7? A configuration problem?

Miscellaneous data

  • My Cygwin is 1.7.5, but it was reproduced with a Cygwin 1.7.7.
  • It works on WinXP, but fails on Cygwin on Windows 7 (32, or 64-bit)
  • The dialog is interesting for dev/debug purposes

I wrote the following C++ program on Visual Studio 2008, in debug (32 bits or 64 bits have the same result):

#include <cstdio>
#include <windows.h>

int main()
{
   printf("It should crash now...") ;
   ::DebugBreak() ;
   return 0 ;
}

The ::DebugBreak()has been replaced by int * p = NULL ; *p = 42 ; (which is supposed to crash with an access violation exception), with exactly the bugged results on Cygwin.

Thanks !

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

I observed the same issue with recent versions of Cygwin. I don't yet know what's causing it, but the Windows SetErrorMode function seems to work a treat:

{
  const UINT oldErrorMode = ::SetErrorMode(0);
  ::DebugBreak();
  ::SetErrorMode(oldErrorMode);
}

Just a tip: if you're using MSVC, use the __debugbreak() intrinsic function instead. It puts the break at that point in the code, rather than inside a function called from there. Some inline assembly might do this trick on other compilers.

share|improve this answer
2  
Just to follow up on this, according to the Windows documentation, a child process inherits its parent's error mode. So obviously Cygwin is setting its error mode to suppress crash dialogs, which is affecting all processes run from a cygwin shell. –  Daryl Dec 1 '10 at 0:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.