GDB (API)
|
00001 /* GDB-friendly replacement for <assert.h>. 00002 Copyright (C) 2000-2013 Free Software Foundation, Inc. 00003 00004 This file is part of GDB. 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00018 00019 #ifndef GDB_ASSERT_H 00020 #define GDB_ASSERT_H 00021 00022 /* A static assertion. This will cause a compile-time error if EXPR, 00023 which must be a compile-time constant, is false. */ 00024 00025 #define gdb_static_assert(expr) \ 00026 extern int never_defined_just_used_for_checking[(expr) ? 1 : -1] 00027 00028 /* PRAGMATICS: "gdb_assert.h":gdb_assert() is a lower case (rather 00029 than upper case) macro since that provides the closest fit to the 00030 existing lower case macro <assert.h>:assert() that it is 00031 replacing. */ 00032 00033 #define gdb_assert(expr) \ 00034 ((void) ((expr) ? 0 : \ 00035 (gdb_assert_fail (#expr, __FILE__, __LINE__, ASSERT_FUNCTION), 0))) 00036 00037 /* Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__' 00038 which contains the name of the function currently being defined. 00039 This is broken in G++ before version 2.6. 00040 C9x has a similar variable called __func__, but prefer the GCC one since 00041 it demangles C++ function names. */ 00042 #if (GCC_VERSION >= 2004) 00043 #define ASSERT_FUNCTION __PRETTY_FUNCTION__ 00044 #else 00045 #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L 00046 #define ASSERT_FUNCTION __func__ 00047 #endif 00048 #endif 00049 00050 /* This prints an "Assertion failed" message, asking the user if they 00051 want to continue, dump core, or just exit. */ 00052 #if defined (ASSERT_FUNCTION) 00053 #define gdb_assert_fail(assertion, file, line, function) \ 00054 internal_error (file, line, _("%s: Assertion `%s' failed."), \ 00055 function, assertion) 00056 #else 00057 #define gdb_assert_fail(assertion, file, line, function) \ 00058 internal_error (file, line, _("Assertion `%s' failed."), \ 00059 assertion) 00060 #endif 00061 00062 /* The canonical form of gdb_assert (0). 00063 MESSAGE is a string to include in the error message. */ 00064 00065 #if defined (ASSERT_FUNCTION) 00066 #define gdb_assert_not_reached(message) \ 00067 internal_error (__FILE__, __LINE__, "%s: %s", ASSERT_FUNCTION, _(message)) 00068 #else 00069 #define gdb_assert_not_reached(message) \ 00070 internal_error (__FILE__, __LINE__, _(message)) 00071 #endif 00072 00073 #endif /* gdb_assert.h */