198944Sobrien/* GDB-friendly replacement for <assert.h>. 298944Sobrien Copyright 2000, 2001 Free Software Foundation, Inc. 398944Sobrien 498944Sobrien This file is part of GDB. 598944Sobrien 698944Sobrien This program is free software; you can redistribute it and/or modify 798944Sobrien it under the terms of the GNU General Public License as published by 898944Sobrien the Free Software Foundation; either version 2 of the License, or 998944Sobrien (at your option) any later version. 1098944Sobrien 1198944Sobrien This program is distributed in the hope that it will be useful, 1298944Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 1398944Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1498944Sobrien GNU General Public License for more details. 1598944Sobrien 1698944Sobrien You should have received a copy of the GNU General Public License 1798944Sobrien along with this program; if not, write to the Free Software 1898944Sobrien Foundation, Inc., 59 Temple Place - Suite 330, 1998944Sobrien Boston, MA 02111-1307, USA. */ 2098944Sobrien 2198944Sobrien#ifndef GDB_ASSERT_H 2298944Sobrien#define GDB_ASSERT_H 2398944Sobrien 2498944Sobrien/* PRAGMATICS: "gdb_assert.h":gdb_assert() is a lower case (rather 2598944Sobrien than upper case) macro since that provides the closest fit to the 2698944Sobrien existing lower case macro <assert.h>:assert() that it is 2798944Sobrien replacing. */ 2898944Sobrien 2998944Sobrien#define gdb_assert(expr) \ 3098944Sobrien ((void) ((expr) ? 0 : \ 3198944Sobrien (gdb_assert_fail (#expr, __FILE__, __LINE__, ASSERT_FUNCTION), 0))) 3298944Sobrien 3398944Sobrien/* Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__' 3498944Sobrien which contains the name of the function currently being defined. 3598944Sobrien This is broken in G++ before version 2.6. 3698944Sobrien C9x has a similar variable called __func__, but prefer the GCC one since 3798944Sobrien it demangles C++ function names. */ 3898944Sobrien#if (GCC_VERSION >= 2004) 3998944Sobrien#define ASSERT_FUNCTION __PRETTY_FUNCTION__ 4098944Sobrien#else 4198944Sobrien#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L 4298944Sobrien#define ASSERT_FUNCTION __func__ 4398944Sobrien#endif 4498944Sobrien#endif 4598944Sobrien 4698944Sobrien/* This prints an "Assertion failed" message, aksing the user if they 4798944Sobrien want to continue, dump core, or just exit. */ 48130803Smarcel#if defined (ASSERT_FUNCTION) 4998944Sobrien#define gdb_assert_fail(assertion, file, line, function) \ 50130803Smarcel internal_error (file, line, "%s: Assertion `%s' failed.", \ 51130803Smarcel function, assertion) 52130803Smarcel#else 53130803Smarcel#define gdb_assert_fail(assertion, file, line, function) \ 54130803Smarcel internal_error (file, line, "Assertion `%s' failed.", \ 5598944Sobrien assertion) 56130803Smarcel#endif 5798944Sobrien 5898944Sobrien#endif /* gdb_assert.h */ 59