xref: /openbsd-src/gnu/gcc/libstdc++-v3/include/debug/debug.h (revision 404b540a9034ac75a6199ad1a32d1bbc7a0d4210)
1*404b540aSrobert // Debugging support implementation -*- C++ -*-
2*404b540aSrobert 
3*404b540aSrobert // Copyright (C) 2003, 2005, 2006
4*404b540aSrobert // Free Software Foundation, Inc.
5*404b540aSrobert //
6*404b540aSrobert // This file is part of the GNU ISO C++ Library.  This library is free
7*404b540aSrobert // software; you can redistribute it and/or modify it under the
8*404b540aSrobert // terms of the GNU General Public License as published by the
9*404b540aSrobert // Free Software Foundation; either version 2, or (at your option)
10*404b540aSrobert // any later version.
11*404b540aSrobert 
12*404b540aSrobert // This library is distributed in the hope that it will be useful,
13*404b540aSrobert // but WITHOUT ANY WARRANTY; without even the implied warranty of
14*404b540aSrobert // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*404b540aSrobert // GNU General Public License for more details.
16*404b540aSrobert 
17*404b540aSrobert // You should have received a copy of the GNU General Public License along
18*404b540aSrobert // with this library; see the file COPYING.  If not, write to the Free
19*404b540aSrobert // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20*404b540aSrobert // USA.
21*404b540aSrobert 
22*404b540aSrobert // As a special exception, you may use this file as part of a free software
23*404b540aSrobert // library without restriction.  Specifically, if other files instantiate
24*404b540aSrobert // templates or use macros or inline functions from this file, or you compile
25*404b540aSrobert // this file and link it with other files to produce an executable, this
26*404b540aSrobert // file does not by itself cause the resulting executable to be covered by
27*404b540aSrobert // the GNU General Public License.  This exception does not however
28*404b540aSrobert // invalidate any other reasons why the executable file might be covered by
29*404b540aSrobert // the GNU General Public License.
30*404b540aSrobert 
31*404b540aSrobert /** @file debug/debug.h
32*404b540aSrobert  *  This file is a GNU debug extension to the Standard C++ Library.
33*404b540aSrobert  */
34*404b540aSrobert 
35*404b540aSrobert #ifndef _GLIBCXX_DEBUG_MACRO_SWITCH_H
36*404b540aSrobert #define _GLIBCXX_DEBUG_MACRO_SWITCH_H 1
37*404b540aSrobert 
38*404b540aSrobert /** Macros and namespaces used by the implementation outside of debug
39*404b540aSrobert  *  wrappers to verify certain properties. The __glibcxx_requires_xxx
40*404b540aSrobert  *  macros are merely wrappers around the __glibcxx_check_xxx wrappers
41*404b540aSrobert  *  when we are compiling with debug mode, but disappear when we are
42*404b540aSrobert  *  in release mode so that there is no checking performed in, e.g.,
43*404b540aSrobert  *  the standard library algorithms.
44*404b540aSrobert */
45*404b540aSrobert 
46*404b540aSrobert // Debug mode namespaces.
47*404b540aSrobert namespace std
48*404b540aSrobert {
49*404b540aSrobert   namespace __debug { }
50*404b540aSrobert }
51*404b540aSrobert 
52*404b540aSrobert namespace __gnu_cxx
53*404b540aSrobert {
54*404b540aSrobert   namespace __debug { };
55*404b540aSrobert }
56*404b540aSrobert 
57*404b540aSrobert namespace __gnu_debug
58*404b540aSrobert {
59*404b540aSrobert   using namespace std::__debug;
60*404b540aSrobert   using namespace __gnu_cxx::__debug;
61*404b540aSrobert }
62*404b540aSrobert 
63*404b540aSrobert #ifndef _GLIBCXX_DEBUG
64*404b540aSrobert 
65*404b540aSrobert # define _GLIBCXX_DEBUG_ASSERT(_Condition)
66*404b540aSrobert # define _GLIBCXX_DEBUG_PEDASSERT(_Condition)
67*404b540aSrobert # define _GLIBCXX_DEBUG_ONLY(_Statement) ;
68*404b540aSrobert # define __glibcxx_requires_cond(_Cond,_Msg)
69*404b540aSrobert # define __glibcxx_requires_valid_range(_First,_Last)
70*404b540aSrobert # define __glibcxx_requires_sorted(_First,_Last)
71*404b540aSrobert # define __glibcxx_requires_sorted_pred(_First,_Last,_Pred)
72*404b540aSrobert # define __glibcxx_requires_partitioned(_First,_Last,_Value)
73*404b540aSrobert # define __glibcxx_requires_partitioned_pred(_First,_Last,_Value,_Pred)
74*404b540aSrobert # define __glibcxx_requires_heap(_First,_Last)
75*404b540aSrobert # define __glibcxx_requires_heap_pred(_First,_Last,_Pred)
76*404b540aSrobert # define __glibcxx_requires_nonempty()
77*404b540aSrobert # define __glibcxx_requires_string(_String)
78*404b540aSrobert # define __glibcxx_requires_string_len(_String,_Len)
79*404b540aSrobert # define __glibcxx_requires_subscript(_N)
80*404b540aSrobert 
81*404b540aSrobert #else
82*404b540aSrobert 
83*404b540aSrobert # include <cstdlib>
84*404b540aSrobert # include <cstdio>
85*404b540aSrobert # include <debug/macros.h>
86*404b540aSrobert 
87*404b540aSrobert namespace std
88*404b540aSrobert {
89*404b540aSrobert   namespace __debug
90*404b540aSrobert   {
91*404b540aSrobert     // Avoid the use of assert, because we're trying to keep the <cassert>
92*404b540aSrobert     // include out of the mix.
93*404b540aSrobert     inline void
__replacement_assert(const char * __file,int __line,const char * __function,const char * __condition)94*404b540aSrobert     __replacement_assert(const char* __file, int __line,
95*404b540aSrobert 			 const char* __function, const char* __condition)
96*404b540aSrobert     {
97*404b540aSrobert       printf("%s:%d: %s: Assertion '%s' failed.\n", __file, __line,
98*404b540aSrobert 	     __function, __condition);
99*404b540aSrobert       abort();
100*404b540aSrobert     }
101*404b540aSrobert   } // namespace __debug
102*404b540aSrobert } // namespace std
103*404b540aSrobert 
104*404b540aSrobert #define _GLIBCXX_DEBUG_ASSERT(_Condition)                                   \
105*404b540aSrobert   do 									    \
106*404b540aSrobert   {									    \
107*404b540aSrobert     if (! (_Condition))                                                     \
108*404b540aSrobert       std::__debug::__replacement_assert(__FILE__, __LINE__,		    \
109*404b540aSrobert 					 __PRETTY_FUNCTION__, #_Condition); \
110*404b540aSrobert   } while (false)
111*404b540aSrobert 
112*404b540aSrobert #ifdef _GLIBCXX_DEBUG_PEDANTIC
113*404b540aSrobert # define _GLIBCXX_DEBUG_PEDASSERT(_Condition) _GLIBCXX_DEBUG_ASSERT(_Condition)
114*404b540aSrobert #else
115*404b540aSrobert # define _GLIBCXX_DEBUG_PEDASSERT(_Condition)
116*404b540aSrobert #endif
117*404b540aSrobert # define _GLIBCXX_DEBUG_ONLY(_Statement) _Statement
118*404b540aSrobert 
119*404b540aSrobert # define __glibcxx_requires_cond(_Cond,_Msg) _GLIBCXX_DEBUG_VERIFY(_Cond,_Msg)
120*404b540aSrobert # define __glibcxx_requires_valid_range(_First,_Last) \
121*404b540aSrobert      __glibcxx_check_valid_range(_First,_Last)
122*404b540aSrobert # define __glibcxx_requires_sorted(_First,_Last) \
123*404b540aSrobert      __glibcxx_check_sorted(_First,_Last)
124*404b540aSrobert # define __glibcxx_requires_sorted_pred(_First,_Last,_Pred) \
125*404b540aSrobert      __glibcxx_check_sorted_pred(_First,_Last,_Pred)
126*404b540aSrobert # define __glibcxx_requires_partitioned(_First,_Last,_Value)	\
127*404b540aSrobert      __glibcxx_check_partitioned(_First,_Last,_Value)
128*404b540aSrobert # define __glibcxx_requires_partitioned_pred(_First,_Last,_Value,_Pred) \
129*404b540aSrobert      __glibcxx_check_partitioned_pred(_First,_Last,_Value,_Pred)
130*404b540aSrobert # define __glibcxx_requires_heap(_First,_Last) \
131*404b540aSrobert      __glibcxx_check_heap(_First,_Last)
132*404b540aSrobert # define __glibcxx_requires_heap_pred(_First,_Last,_Pred) \
133*404b540aSrobert      __glibcxx_check_heap_pred(_First,_Last,_Pred)
134*404b540aSrobert # define __glibcxx_requires_nonempty() __glibcxx_check_nonempty()
135*404b540aSrobert # define __glibcxx_requires_string(_String) __glibcxx_check_string(_String)
136*404b540aSrobert # define __glibcxx_requires_string_len(_String,_Len)	\
137*404b540aSrobert      __glibcxx_check_string_len(_String,_Len)
138*404b540aSrobert # define __glibcxx_requires_subscript(_N) __glibcxx_check_subscript(_N)
139*404b540aSrobert 
140*404b540aSrobert # include <debug/functions.h>
141*404b540aSrobert # include <debug/formatter.h>
142*404b540aSrobert 
143*404b540aSrobert #endif
144*404b540aSrobert 
145*404b540aSrobert #endif // _GLIBCXX_DEBUG_MACRO_SWITCH_H
146