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