2000-02-18 03:38:33 +08:00
|
|
|
/* assert.cc: Handle the assert macro for WIN32.
|
|
|
|
|
2013-11-24 20:13:36 +08:00
|
|
|
Copyright 1997, 1998, 2000, 2001, 2002, 2007, 2008, 2009, 2011, 2013
|
|
|
|
Red Hat, Inc.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
#include "winsup.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
/* This function is called when the assert macro fails. This will
|
|
|
|
override the function of the same name in newlib. */
|
|
|
|
|
|
|
|
extern "C" void
|
|
|
|
__assert (const char *file, int line, const char *failedexpr)
|
2007-06-27 20:46:35 +08:00
|
|
|
{
|
|
|
|
__assert_func (file, line, NULL, failedexpr);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void
|
|
|
|
__assert_func (const char *file, int line, const char *func,
|
|
|
|
const char *failedexpr)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
HANDLE h;
|
|
|
|
|
|
|
|
/* If we don't have a console in a Windows program, then bring up a
|
|
|
|
message box for the assertion failure. */
|
|
|
|
|
2011-07-04 23:25:36 +08:00
|
|
|
h = CreateFile ("CONOUT$", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
&sec_none_nih, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
2002-09-19 23:12:48 +08:00
|
|
|
if (h == INVALID_HANDLE_VALUE)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2011-05-01 22:35:12 +08:00
|
|
|
PWCHAR buf = (PWCHAR) alloca ((100 + strlen (failedexpr))
|
|
|
|
* sizeof (WCHAR));
|
|
|
|
__small_swprintf (buf,
|
|
|
|
L"Failed assertion\n\t%s\nat line %d of file %s%s%s",
|
|
|
|
failedexpr, line, file,
|
|
|
|
func ? "\nin function " : "", func ? func : "");
|
|
|
|
MessageBoxW (NULL, buf, NULL, MB_OK | MB_ICONERROR | MB_TASKMODAL);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CloseHandle (h);
|
2007-06-27 20:46:35 +08:00
|
|
|
small_printf ("assertion \"%s\" failed: file \"%s\", line %d%s%s\n",
|
|
|
|
failedexpr, file, line,
|
|
|
|
func ? ", function: " : "", func ? func : "");
|
2011-11-14 09:29:49 +08:00
|
|
|
debug_printf ("assertion \"%s\" failed: file \"%s\", line %d%s%s",
|
|
|
|
failedexpr, file, line,
|
|
|
|
func ? ", function: " : "", func ? func : "");
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2002-08-12 03:19:29 +08:00
|
|
|
#ifdef DEBUGGING
|
|
|
|
try_to_debug ();
|
|
|
|
#endif
|
2000-09-03 12:16:35 +08:00
|
|
|
abort (); // FIXME: Someday this should work.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|