xref: /netbsd-src/external/gpl3/gdb/dist/gdbsupport/gdb_assert.h (revision 3117ece4fc4a4ca4489ba793710b60b0d26bab6c)
1 /* GDB-friendly replacement for <assert.h>.
2    Copyright (C) 2000-2024 Free Software Foundation, Inc.
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
8    the Free Software Foundation; either version 3 of the License, or
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
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18 
19 #ifndef COMMON_GDB_ASSERT_H
20 #define COMMON_GDB_ASSERT_H
21 
22 #include "errors.h"
23 
24 /* PRAGMATICS: "gdb_assert.h":gdb_assert() is a lower case (rather
25    than upper case) macro since that provides the closest fit to the
26    existing lower case macro <assert.h>:assert() that it is
27    replacing.  */
28 
29 #define gdb_assert(expr)                                                      \
30   ((void) ((expr) ? 0 :                                                       \
31 	   (gdb_assert_fail (#expr, __FILE__, __LINE__, __func__), 0)))
32 
33 /* This prints an "Assertion failed" message, asking the user if they
34    want to continue, dump core, or just exit.  */
35 #define gdb_assert_fail(assertion, file, line, function)                      \
36   internal_error_loc (file, line, _("%s: Assertion `%s' failed."),                \
37 		      function, assertion)
38 
39 /* The canonical form of gdb_assert (0).
40    MESSAGE is a string to include in the error message.  */
41 
42 #define gdb_assert_not_reached(message, ...) \
43   internal_error_loc (__FILE__, __LINE__, _("%s: " message), __func__, \
44 		      ##__VA_ARGS__)
45 
46 #endif /* COMMON_GDB_ASSERT_H */
47