Commit | Line | Data |
---|---|---|
6751bfc9 | 1 | /* GDB-friendly replacement for <assert.h>. |
7b6bb8da | 2 | Copyright (C) 2000, 2001, 2007, 2008, 2009, 2010, 2011 |
4c38e0a4 | 3 | Free Software Foundation, Inc. |
6751bfc9 MK |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
6751bfc9 MK |
10 | (at your option) any later version. |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
6751bfc9 MK |
19 | |
20 | #ifndef GDB_ASSERT_H | |
21 | #define GDB_ASSERT_H | |
22 | ||
f5afdc18 TT |
23 | /* A static assertion. This will cause a compile-time error if EXPR, |
24 | which must be a compile-time constant, is false. */ | |
25 | ||
26 | #define static_assert(expr) \ | |
27 | extern int never_defined_just_used_for_checking[(expr) ? 1 : -1] | |
28 | ||
38266776 AC |
29 | /* PRAGMATICS: "gdb_assert.h":gdb_assert() is a lower case (rather |
30 | than upper case) macro since that provides the closest fit to the | |
31 | existing lower case macro <assert.h>:assert() that it is | |
0963b4bd | 32 | replacing. */ |
38266776 | 33 | |
6751bfc9 MK |
34 | #define gdb_assert(expr) \ |
35 | ((void) ((expr) ? 0 : \ | |
36 | (gdb_assert_fail (#expr, __FILE__, __LINE__, ASSERT_FUNCTION), 0))) | |
37 | ||
38 | /* Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__' | |
39 | which contains the name of the function currently being defined. | |
40 | This is broken in G++ before version 2.6. | |
41 | C9x has a similar variable called __func__, but prefer the GCC one since | |
42 | it demangles C++ function names. */ | |
43 | #if (GCC_VERSION >= 2004) | |
44 | #define ASSERT_FUNCTION __PRETTY_FUNCTION__ | |
45 | #else | |
46 | #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L | |
47 | #define ASSERT_FUNCTION __func__ | |
6751bfc9 MK |
48 | #endif |
49 | #endif | |
50 | ||
f3574227 | 51 | /* This prints an "Assertion failed" message, asking the user if they |
6751bfc9 | 52 | want to continue, dump core, or just exit. */ |
93ec1121 AC |
53 | #if defined (ASSERT_FUNCTION) |
54 | #define gdb_assert_fail(assertion, file, line, function) \ | |
3e43a32a | 55 | internal_error (file, line, _("%s: Assertion `%s' failed."), \ |
93ec1121 AC |
56 | function, assertion) |
57 | #else | |
6751bfc9 | 58 | #define gdb_assert_fail(assertion, file, line, function) \ |
3e43a32a | 59 | internal_error (file, line, _("Assertion `%s' failed."), \ |
6751bfc9 | 60 | assertion) |
93ec1121 | 61 | #endif |
6751bfc9 | 62 | |
f3574227 DE |
63 | /* The canonical form of gdb_assert (0). |
64 | MESSAGE is a string to include in the error message. */ | |
65 | ||
66 | #if defined (ASSERT_FUNCTION) | |
67 | #define gdb_assert_not_reached(message) \ | |
68 | internal_error (__FILE__, __LINE__, "%s: %s", ASSERT_FUNCTION, _(message)) | |
69 | #else | |
70 | #define gdb_assert_not_reached(message) \ | |
71 | internal_error (__FILE__, __LINE__, _(message)) | |
72 | #endif | |
73 | ||
6751bfc9 | 74 | #endif /* gdb_assert.h */ |