2009-12-02 Tristan Gingold <gingold@adacore.com>
[deliverable/binutils-gdb.git] / gdb / gdb_assert.h
CommitLineData
6751bfc9 1/* GDB-friendly replacement for <assert.h>.
0fb0cc75 2 Copyright (C) 2000, 2001, 2007, 2008, 2009 Free Software Foundation, Inc.
6751bfc9
MK
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
a9762ec7 8 the Free Software Foundation; either version 3 of the License, or
6751bfc9
MK
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
a9762ec7 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
6751bfc9
MK
18
19#ifndef GDB_ASSERT_H
20#define GDB_ASSERT_H
21
38266776
AC
22/* PRAGMATICS: "gdb_assert.h":gdb_assert() is a lower case (rather
23 than upper case) macro since that provides the closest fit to the
24 existing lower case macro <assert.h>:assert() that it is
25 replacing. */
26
6751bfc9
MK
27#define gdb_assert(expr) \
28 ((void) ((expr) ? 0 : \
29 (gdb_assert_fail (#expr, __FILE__, __LINE__, ASSERT_FUNCTION), 0)))
30
31/* Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__'
32 which contains the name of the function currently being defined.
33 This is broken in G++ before version 2.6.
34 C9x has a similar variable called __func__, but prefer the GCC one since
35 it demangles C++ function names. */
36#if (GCC_VERSION >= 2004)
37#define ASSERT_FUNCTION __PRETTY_FUNCTION__
38#else
39#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
40#define ASSERT_FUNCTION __func__
6751bfc9
MK
41#endif
42#endif
43
44/* This prints an "Assertion failed" message, aksing the user if they
45 want to continue, dump core, or just exit. */
93ec1121
AC
46#if defined (ASSERT_FUNCTION)
47#define gdb_assert_fail(assertion, file, line, function) \
e2e0b3e5 48 internal_error (file, line, _("%s: Assertion `%s' failed."), \
93ec1121
AC
49 function, assertion)
50#else
6751bfc9 51#define gdb_assert_fail(assertion, file, line, function) \
e2e0b3e5 52 internal_error (file, line, _("Assertion `%s' failed."), \
6751bfc9 53 assertion)
93ec1121 54#endif
6751bfc9
MK
55
56#endif /* gdb_assert.h */
This page took 0.793916 seconds and 4 git commands to generate.