xref: /netbsd-src/external/gpl3/gdb/dist/gdbsupport/gdb_assert.h (revision 5ba1f45f2a09259cc846f20c7c5501604d633c90)
18dffb485Schristos /* GDB-friendly replacement for <assert.h>.
2*5ba1f45fSchristos    Copyright (C) 2000-2024 Free Software Foundation, Inc.
38dffb485Schristos 
48dffb485Schristos    This file is part of GDB.
58dffb485Schristos 
68dffb485Schristos    This program is free software; you can redistribute it and/or modify
78dffb485Schristos    it under the terms of the GNU General Public License as published by
88dffb485Schristos    the Free Software Foundation; either version 3 of the License, or
98dffb485Schristos    (at your option) any later version.
108dffb485Schristos 
118dffb485Schristos    This program is distributed in the hope that it will be useful,
128dffb485Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
138dffb485Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
148dffb485Schristos    GNU General Public License for more details.
158dffb485Schristos 
168dffb485Schristos    You should have received a copy of the GNU General Public License
178dffb485Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
188dffb485Schristos 
198dffb485Schristos #ifndef COMMON_GDB_ASSERT_H
208dffb485Schristos #define COMMON_GDB_ASSERT_H
218dffb485Schristos 
228dffb485Schristos #include "errors.h"
238dffb485Schristos 
248dffb485Schristos /* PRAGMATICS: "gdb_assert.h":gdb_assert() is a lower case (rather
258dffb485Schristos    than upper case) macro since that provides the closest fit to the
268dffb485Schristos    existing lower case macro <assert.h>:assert() that it is
278dffb485Schristos    replacing.  */
288dffb485Schristos 
298dffb485Schristos #define gdb_assert(expr)                                                      \
308dffb485Schristos   ((void) ((expr) ? 0 :                                                       \
314b169a6bSchristos 	   (gdb_assert_fail (#expr, __FILE__, __LINE__, __func__), 0)))
328dffb485Schristos 
338dffb485Schristos /* This prints an "Assertion failed" message, asking the user if they
348dffb485Schristos    want to continue, dump core, or just exit.  */
358dffb485Schristos #define gdb_assert_fail(assertion, file, line, function)                      \
364b169a6bSchristos   internal_error_loc (file, line, _("%s: Assertion `%s' failed."),                \
378dffb485Schristos 		      function, assertion)
388dffb485Schristos 
398dffb485Schristos /* The canonical form of gdb_assert (0).
408dffb485Schristos    MESSAGE is a string to include in the error message.  */
418dffb485Schristos 
424b169a6bSchristos #define gdb_assert_not_reached(message, ...) \
434b169a6bSchristos   internal_error_loc (__FILE__, __LINE__, _("%s: " message), __func__, \
444b169a6bSchristos 		      ##__VA_ARGS__)
458dffb485Schristos 
468dffb485Schristos #endif /* COMMON_GDB_ASSERT_H */
47