summaryrefslogtreecommitdiff
path: root/libshouldbeinlibc/assert-backtrace.h
blob: f49a537ea5af5ae1c501e912977acd36e57b35f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* Augment failing assertions with backtraces.

   Copyright (C) 1994-2015 Free Software Foundation, Inc.

   This file is part of the GNU Hurd.

   The GNU Hurd is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2, or (at
   your option) any later version.

   The GNU Hurd is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with the GNU Hurd.  If not, see <http://www.gnu.org/licenses/>.  */

#ifndef __ASSERT_BACKTRACE__
#define __ASSERT_BACKTRACE__

#ifdef NDEBUG

#define assert_backtrace(expr)		((void) 0)
#define assert_perror_backtrace(errnum)	((void) 0)

#else /* NDEBUG */

#include <sys/cdefs.h>

/* This prints an "Assertion failed" message, prints a stack trace,
   and aborts.	*/
void __assert_fail_backtrace (const char *assertion,
			      const char *file,
			      unsigned int line,
			      const char *function)
  __attribute__ ((noreturn, unused));

/* Likewise, but prints the error text for ERRNUM.  */
void __assert_perror_fail_backtrace (int errnum,
				     const char *file,
				     unsigned int line,
				     const char *function)
  __attribute__ ((noreturn, unused));

#define assert_backtrace(expr)						\
  ((expr)								\
   ? (void) 0								\
   : __assert_fail_backtrace (__STRING(expr),				\
			      __FILE__, __LINE__,			\
			      __PRETTY_FUNCTION__))

#define assert_perror_backtrace(expr)					\
  ((expr == 0)								\
   ? (void) 0								\
   : __assert_perror_fail_backtrace (expr,				\
				     __FILE__, __LINE__,		\
				     __PRETTY_FUNCTION__))

#endif /* NDEBUG */
#endif /* __ASSERT_BACKTRACE__ */