1226026Sdelphij// Debugging support implementation -*- C++ -*-
2226026Sdelphij
3226026Sdelphij// Copyright (C) 2003, 2005, 2006
4226026Sdelphij// Free Software Foundation, Inc.
5226026Sdelphij//
6226026Sdelphij// This file is part of the GNU ISO C++ Library.  This library is free
7226026Sdelphij// software; you can redistribute it and/or modify it under the
8226026Sdelphij// terms of the GNU General Public License as published by the
9226026Sdelphij// Free Software Foundation; either version 2, or (at your option)
10226026Sdelphij// any later version.
11226026Sdelphij
12226026Sdelphij// This library is distributed in the hope that it will be useful,
13226026Sdelphij// but WITHOUT ANY WARRANTY; without even the implied warranty of
14226026Sdelphij// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15226026Sdelphij// GNU General Public License for more details.
16226026Sdelphij
17226026Sdelphij// You should have received a copy of the GNU General Public License along
18226026Sdelphij// with this library; see the file COPYING.  If not, write to the Free
19226026Sdelphij// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20226026Sdelphij// USA.
21226026Sdelphij
22226026Sdelphij// As a special exception, you may use this file as part of a free software
23226026Sdelphij// library without restriction.  Specifically, if other files instantiate
24226026Sdelphij// templates or use macros or inline functions from this file, or you compile
25226026Sdelphij// this file and link it with other files to produce an executable, this
26226026Sdelphij// file does not by itself cause the resulting executable to be covered by
27226026Sdelphij// the GNU General Public License.  This exception does not however
28226026Sdelphij// invalidate any other reasons why the executable file might be covered by
29226026Sdelphij// the GNU General Public License.
30226026Sdelphij
31226026Sdelphij/** @file debug/debug.h
32226026Sdelphij *  This file is a GNU debug extension to the Standard C++ Library.
33226026Sdelphij */
34226026Sdelphij
35226026Sdelphij#ifndef _GLIBCXX_DEBUG_MACRO_SWITCH_H
36226026Sdelphij#define _GLIBCXX_DEBUG_MACRO_SWITCH_H 1
37226026Sdelphij
38226026Sdelphij/** Macros and namespaces used by the implementation outside of debug
39226026Sdelphij *  wrappers to verify certain properties. The __glibcxx_requires_xxx
40226026Sdelphij *  macros are merely wrappers around the __glibcxx_check_xxx wrappers
41226026Sdelphij *  when we are compiling with debug mode, but disappear when we are
42226026Sdelphij *  in release mode so that there is no checking performed in, e.g.,
43226026Sdelphij *  the standard library algorithms.
44226026Sdelphij*/
45226026Sdelphij
46226026Sdelphij// Debug mode namespaces.
47226026Sdelphijnamespace std
48226026Sdelphij{
49226026Sdelphij  namespace __debug { }
50226026Sdelphij}
51226026Sdelphij
52226026Sdelphijnamespace __gnu_cxx
53226026Sdelphij{
54226026Sdelphij  namespace __debug { };
55226026Sdelphij}
56226026Sdelphij
57226026Sdelphijnamespace __gnu_debug
58226026Sdelphij{
59226026Sdelphij  using namespace std::__debug;
60226026Sdelphij  using namespace __gnu_cxx::__debug;
61226026Sdelphij}
62226026Sdelphij
63226026Sdelphij#ifndef _GLIBCXX_DEBUG
64226026Sdelphij
65226026Sdelphij# define _GLIBCXX_DEBUG_ASSERT(_Condition)
66226026Sdelphij# define _GLIBCXX_DEBUG_PEDASSERT(_Condition)
67226026Sdelphij# define _GLIBCXX_DEBUG_ONLY(_Statement) ;
68226026Sdelphij# define __glibcxx_requires_cond(_Cond,_Msg)
69226026Sdelphij# define __glibcxx_requires_valid_range(_First,_Last)
70226026Sdelphij# define __glibcxx_requires_sorted(_First,_Last)
71226026Sdelphij# define __glibcxx_requires_sorted_pred(_First,_Last,_Pred)
72226026Sdelphij# define __glibcxx_requires_partitioned(_First,_Last,_Value)
73226026Sdelphij# define __glibcxx_requires_partitioned_pred(_First,_Last,_Value,_Pred)
74226026Sdelphij# define __glibcxx_requires_heap(_First,_Last)
75226026Sdelphij# define __glibcxx_requires_heap_pred(_First,_Last,_Pred)
76226026Sdelphij# define __glibcxx_requires_nonempty()
77235317Sgjb# define __glibcxx_requires_string(_String)
78226026Sdelphij# define __glibcxx_requires_string_len(_String,_Len)
79226026Sdelphij# define __glibcxx_requires_subscript(_N)
80226026Sdelphij
81226026Sdelphij#else
82226026Sdelphij
83235317Sgjb# include <cstdlib>
84226026Sdelphij# include <cstdio>
85226026Sdelphij# include <debug/macros.h>
86226026Sdelphij
87226026Sdelphijnamespace std
88226026Sdelphij{
89226026Sdelphij  namespace __debug
90226026Sdelphij  {
91226026Sdelphij    // Avoid the use of assert, because we're trying to keep the <cassert>
92226026Sdelphij    // include out of the mix.
93226026Sdelphij    inline void
94226026Sdelphij    __replacement_assert(const char* __file, int __line,
95226026Sdelphij			 const char* __function, const char* __condition)
96226026Sdelphij    {
97226026Sdelphij      printf("%s:%d: %s: Assertion '%s' failed.\n", __file, __line,
98226026Sdelphij	     __function, __condition);
99226026Sdelphij      abort();
100226026Sdelphij    }
101226026Sdelphij  } // namespace __debug
102226026Sdelphij} // namespace std
103226026Sdelphij
104226026Sdelphij#define _GLIBCXX_DEBUG_ASSERT(_Condition)                                   \
105226026Sdelphij  do 									    \
106226026Sdelphij  {									    \
107226026Sdelphij    if (! (_Condition))                                                     \
108226026Sdelphij      std::__debug::__replacement_assert(__FILE__, __LINE__,		    \
109226026Sdelphij					 __PRETTY_FUNCTION__, #_Condition); \
110226026Sdelphij  } while (false)
111226026Sdelphij
112226026Sdelphij#ifdef _GLIBCXX_DEBUG_PEDANTIC
113226026Sdelphij# define _GLIBCXX_DEBUG_PEDASSERT(_Condition) _GLIBCXX_DEBUG_ASSERT(_Condition)
114226026Sdelphij#else
115226026Sdelphij# define _GLIBCXX_DEBUG_PEDASSERT(_Condition)
116226026Sdelphij#endif
117267938Sbapt# define _GLIBCXX_DEBUG_ONLY(_Statement) _Statement
118226026Sdelphij
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