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