xref: /netbsd-src/external/gpl3/gdb.old/dist/gdbsupport/gdb_assert.h (revision 6881a4007f077b54e5f51159c52b9b25f57deb0d)
17d62b00eSchristos /* GDB-friendly replacement for <assert.h>.
2*6881a400Schristos    Copyright (C) 2000-2023 Free Software Foundation, Inc.
37d62b00eSchristos 
47d62b00eSchristos    This file is part of GDB.
57d62b00eSchristos 
67d62b00eSchristos    This program is free software; you can redistribute it and/or modify
77d62b00eSchristos    it under the terms of the GNU General Public License as published by
87d62b00eSchristos    the Free Software Foundation; either version 3 of the License, or
97d62b00eSchristos    (at your option) any later version.
107d62b00eSchristos 
117d62b00eSchristos    This program is distributed in the hope that it will be useful,
127d62b00eSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
137d62b00eSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
147d62b00eSchristos    GNU General Public License for more details.
157d62b00eSchristos 
167d62b00eSchristos    You should have received a copy of the GNU General Public License
177d62b00eSchristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
187d62b00eSchristos 
197d62b00eSchristos #ifndef COMMON_GDB_ASSERT_H
207d62b00eSchristos #define COMMON_GDB_ASSERT_H
217d62b00eSchristos 
227d62b00eSchristos #include "errors.h"
237d62b00eSchristos 
247d62b00eSchristos /* A static assertion.  This will cause a compile-time error if EXPR,
257d62b00eSchristos    which must be a compile-time constant, is false.  */
267d62b00eSchristos 
277d62b00eSchristos #define gdb_static_assert(expr) static_assert (expr, "")
287d62b00eSchristos 
297d62b00eSchristos /* PRAGMATICS: "gdb_assert.h":gdb_assert() is a lower case (rather
307d62b00eSchristos    than upper case) macro since that provides the closest fit to the
317d62b00eSchristos    existing lower case macro <assert.h>:assert() that it is
327d62b00eSchristos    replacing.  */
337d62b00eSchristos 
347d62b00eSchristos #define gdb_assert(expr)                                                      \
357d62b00eSchristos   ((void) ((expr) ? 0 :                                                       \
36*6881a400Schristos 	   (gdb_assert_fail (#expr, __FILE__, __LINE__, __func__), 0)))
377d62b00eSchristos 
387d62b00eSchristos /* This prints an "Assertion failed" message, asking the user if they
397d62b00eSchristos    want to continue, dump core, or just exit.  */
407d62b00eSchristos #define gdb_assert_fail(assertion, file, line, function)                      \
41*6881a400Schristos   internal_error_loc (file, line, _("%s: Assertion `%s' failed."),                \
427d62b00eSchristos 		      function, assertion)
437d62b00eSchristos 
447d62b00eSchristos /* The canonical form of gdb_assert (0).
457d62b00eSchristos    MESSAGE is a string to include in the error message.  */
467d62b00eSchristos 
47*6881a400Schristos #define gdb_assert_not_reached(message, ...) \
48*6881a400Schristos   internal_error_loc (__FILE__, __LINE__, _("%s: " message), __func__, \
49*6881a400Schristos 		      ##__VA_ARGS__)
507d62b00eSchristos 
517d62b00eSchristos #endif /* COMMON_GDB_ASSERT_H */
52