debug.h

Go to the documentation of this file.
00001 // Debugging support implementation -*- C++ -*-
00002 
00003 // Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
00004 // Free Software Foundation, Inc.
00005 //
00006 // This file is part of the GNU ISO C++ Library.  This library is free
00007 // software; you can redistribute it and/or modify it under the
00008 // terms of the GNU General Public License as published by the
00009 // Free Software Foundation; either version 2, or (at your option)
00010 // any later version.
00011 
00012 // This library is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 
00017 // You should have received a copy of the GNU General Public License along
00018 // with this library; see the file COPYING.  If not, write to the Free
00019 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00020 // USA.
00021 
00022 // As a special exception, you may use this file as part of a free software
00023 // library without restriction.  Specifically, if other files instantiate
00024 // templates or use macros or inline functions from this file, or you compile
00025 // this file and link it with other files to produce an executable, this
00026 // file does not by itself cause the resulting executable to be covered by
00027 // the GNU General Public License.  This exception does not however
00028 // invalidate any other reasons why the executable file might be covered by
00029 // the GNU General Public License.
00030 
00031 /** @file debug/debug.h
00032  *  This file is a GNU debug extension to the Standard C++ Library.
00033  */
00034 
00035 #ifndef _GLIBCXX_DEBUG_MACRO_SWITCH_H
00036 #define _GLIBCXX_DEBUG_MACRO_SWITCH_H 1
00037 
00038 /** Macros and namespaces used by the implementation outside of debug
00039  *  wrappers to verify certain properties. The __glibcxx_requires_xxx
00040  *  macros are merely wrappers around the __glibcxx_check_xxx wrappers
00041  *  when we are compiling with debug mode, but disappear when we are
00042  *  in release mode so that there is no checking performed in, e.g.,
00043  *  the standard library algorithms.
00044 */
00045 
00046 // Debug mode namespaces.
00047 
00048 /**
00049  * @namespace std::__debug
00050  * @brief GNU debug code, replaces standard behavior with debug behavior.
00051  */
00052 namespace std 
00053 { 
00054   namespace __debug { } 
00055 }
00056 
00057 /** @namespace __gnu_debug
00058  *  @brief GNU debug classes for public use.
00059 */
00060 namespace __gnu_debug
00061 {
00062   using namespace std::__debug;
00063 }
00064 
00065 #ifndef _GLIBCXX_DEBUG
00066 
00067 # define _GLIBCXX_DEBUG_ASSERT(_Condition)
00068 # define _GLIBCXX_DEBUG_PEDASSERT(_Condition)
00069 # define _GLIBCXX_DEBUG_ONLY(_Statement) ;
00070 # define __glibcxx_requires_cond(_Cond,_Msg)
00071 # define __glibcxx_requires_valid_range(_First,_Last)
00072 # define __glibcxx_requires_sorted(_First,_Last)
00073 # define __glibcxx_requires_sorted_pred(_First,_Last,_Pred)
00074 # define __glibcxx_requires_sorted_set(_First1,_Last1,_First2)
00075 # define __glibcxx_requires_sorted_set_pred(_First1,_Last1,_First2,_Pred)
00076 # define __glibcxx_requires_partitioned_lower(_First,_Last,_Value)
00077 # define __glibcxx_requires_partitioned_upper(_First,_Last,_Value)
00078 # define __glibcxx_requires_partitioned_lower_pred(_First,_Last,_Value,_Pred)
00079 # define __glibcxx_requires_partitioned_upper_pred(_First,_Last,_Value,_Pred)
00080 # define __glibcxx_requires_heap(_First,_Last)
00081 # define __glibcxx_requires_heap_pred(_First,_Last,_Pred)
00082 # define __glibcxx_requires_nonempty()
00083 # define __glibcxx_requires_string(_String)
00084 # define __glibcxx_requires_string_len(_String,_Len)
00085 # define __glibcxx_requires_subscript(_N)
00086 
00087 #else
00088 
00089 # include <cstdio>
00090 # include <debug/macros.h>
00091 
00092 namespace std
00093 {
00094   namespace __debug
00095   { 
00096     // Avoid the use of assert, because we're trying to keep the <cassert>
00097     // include out of the mix.
00098     inline void
00099     __replacement_assert(const char* __file, int __line, 
00100              const char* __function, const char* __condition)
00101     {
00102       printf("%s:%d: %s: Assertion '%s' failed.\n", __file, __line,
00103          __function, __condition);
00104       __builtin_abort();
00105     }
00106   } // namespace __debug
00107 } // namespace std
00108 
00109 #define _GLIBCXX_DEBUG_ASSERT(_Condition)                                   \
00110   do                                        \
00111   {                                     \
00112     if (! (_Condition))                                                     \
00113       std::__debug::__replacement_assert(__FILE__, __LINE__,            \
00114                      __PRETTY_FUNCTION__, #_Condition); \
00115   } while (false)
00116 
00117 #ifdef _GLIBCXX_DEBUG_PEDANTIC
00118 # define _GLIBCXX_DEBUG_PEDASSERT(_Condition) _GLIBCXX_DEBUG_ASSERT(_Condition)
00119 #else
00120 # define _GLIBCXX_DEBUG_PEDASSERT(_Condition)
00121 #endif
00122 
00123 # define _GLIBCXX_DEBUG_ONLY(_Statement) _Statement
00124 
00125 # define __glibcxx_requires_cond(_Cond,_Msg) _GLIBCXX_DEBUG_VERIFY(_Cond,_Msg)
00126 # define __glibcxx_requires_valid_range(_First,_Last) \
00127      __glibcxx_check_valid_range(_First,_Last)
00128 # define __glibcxx_requires_sorted(_First,_Last) \
00129      __glibcxx_check_sorted(_First,_Last)
00130 # define __glibcxx_requires_sorted_pred(_First,_Last,_Pred) \
00131      __glibcxx_check_sorted_pred(_First,_Last,_Pred)
00132 # define __glibcxx_requires_sorted_set(_First1,_Last1,_First2) \
00133      __glibcxx_check_sorted_set(_First1,_Last1,_First2)
00134 # define __glibcxx_requires_sorted_set_pred(_First1,_Last1,_First2,_Pred) \
00135      __glibcxx_check_sorted_set_pred(_First1,_Last1,_First2,_Pred)
00136 # define __glibcxx_requires_partitioned_lower(_First,_Last,_Value)  \
00137      __glibcxx_check_partitioned_lower(_First,_Last,_Value)
00138 # define __glibcxx_requires_partitioned_upper(_First,_Last,_Value)  \
00139      __glibcxx_check_partitioned_upper(_First,_Last,_Value)
00140 # define __glibcxx_requires_partitioned_lower_pred(_First,_Last,_Value,_Pred) \
00141      __glibcxx_check_partitioned_lower_pred(_First,_Last,_Value,_Pred)
00142 # define __glibcxx_requires_partitioned_upper_pred(_First,_Last,_Value,_Pred) \
00143      __glibcxx_check_partitioned_upper_pred(_First,_Last,_Value,_Pred)
00144 # define __glibcxx_requires_heap(_First,_Last) \
00145      __glibcxx_check_heap(_First,_Last)
00146 # define __glibcxx_requires_heap_pred(_First,_Last,_Pred) \
00147      __glibcxx_check_heap_pred(_First,_Last,_Pred)
00148 # define __glibcxx_requires_nonempty() __glibcxx_check_nonempty()
00149 # define __glibcxx_requires_string(_String) __glibcxx_check_string(_String)
00150 # define __glibcxx_requires_string_len(_String,_Len)    \
00151      __glibcxx_check_string_len(_String,_Len)
00152 # define __glibcxx_requires_subscript(_N) __glibcxx_check_subscript(_N)
00153 
00154 # include <debug/functions.h>
00155 # include <debug/formatter.h>
00156 
00157 #endif
00158 
00159 #endif // _GLIBCXX_DEBUG_MACRO_SWITCH_H

Generated on Wed Mar 26 00:42:56 2008 for libstdc++ by  doxygen 1.5.1