]>
Commit | Line | Data |
---|---|---|
1fd5e000 CF |
1 | /* assert.cc: Handle the assert macro for WIN32. |
2 | ||
bc837d22 | 3 | Copyright 1997, 1998, 2000, 2001, 2002, 2007, 2008, 2009, 2011 Red Hat, Inc. |
1fd5e000 CF |
4 | |
5 | This file is part of Cygwin. | |
6 | ||
7 | This software is a copyrighted work licensed under the terms of the | |
8 | Cygwin license. Please consult the file "CYGWIN_LICENSE" for | |
9 | details. */ | |
10 | ||
11 | #include "winsup.h" | |
d0b178fe DD |
12 | #include <wingdi.h> |
13 | #include <winuser.h> | |
1fd5e000 CF |
14 | |
15 | #include <assert.h> | |
16 | #include <stdlib.h> | |
1fd5e000 CF |
17 | |
18 | /* This function is called when the assert macro fails. This will | |
19 | override the function of the same name in newlib. */ | |
20 | ||
21 | extern "C" void | |
22 | __assert (const char *file, int line, const char *failedexpr) | |
048e00e0 EB |
23 | { |
24 | __assert_func (file, line, NULL, failedexpr); | |
25 | } | |
26 | ||
27 | extern "C" void | |
28 | __assert_func (const char *file, int line, const char *func, | |
29 | const char *failedexpr) | |
1fd5e000 CF |
30 | { |
31 | HANDLE h; | |
32 | ||
33 | /* If we don't have a console in a Windows program, then bring up a | |
34 | message box for the assertion failure. */ | |
35 | ||
fc3e7da6 CV |
36 | h = CreateFile ("CONOUT$", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, |
37 | &sec_none_nih, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | |
580e99a1 | 38 | if (h == INVALID_HANDLE_VALUE) |
1fd5e000 | 39 | { |
79e741ef CV |
40 | PWCHAR buf = (PWCHAR) alloca ((100 + strlen (failedexpr)) |
41 | * sizeof (WCHAR)); | |
42 | __small_swprintf (buf, | |
43 | L"Failed assertion\n\t%s\nat line %d of file %s%s%s", | |
44 | failedexpr, line, file, | |
45 | func ? "\nin function " : "", func ? func : ""); | |
46 | MessageBoxW (NULL, buf, NULL, MB_OK | MB_ICONERROR | MB_TASKMODAL); | |
1fd5e000 CF |
47 | } |
48 | else | |
49 | { | |
50 | CloseHandle (h); | |
048e00e0 EB |
51 | small_printf ("assertion \"%s\" failed: file \"%s\", line %d%s%s\n", |
52 | failedexpr, file, line, | |
53 | func ? ", function: " : "", func ? func : ""); | |
56a19715 CF |
54 | debug_printf ("assertion \"%s\" failed: file \"%s\", line %d%s%s", |
55 | failedexpr, file, line, | |
56 | func ? ", function: " : "", func ? func : ""); | |
1fd5e000 CF |
57 | } |
58 | ||
3cb62bd6 CF |
59 | #ifdef DEBUGGING |
60 | try_to_debug (); | |
61 | #endif | |
b0e82b74 | 62 | abort (); // FIXME: Someday this should work. |
1fd5e000 CF |
63 | |
64 | /* NOTREACHED */ | |
65 | } |