1132720Skan// Debugging support implementation -*- C++ -*- 2132720Skan 3169691Skan// Copyright (C) 2003, 2005, 2006 4132720Skan// Free Software Foundation, Inc. 5132720Skan// 6132720Skan// This file is part of the GNU ISO C++ Library. This library is free 7132720Skan// software; you can redistribute it and/or modify it under the 8132720Skan// terms of the GNU General Public License as published by the 9132720Skan// Free Software Foundation; either version 2, or (at your option) 10132720Skan// any later version. 11132720Skan 12132720Skan// This library is distributed in the hope that it will be useful, 13132720Skan// but WITHOUT ANY WARRANTY; without even the implied warranty of 14132720Skan// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15132720Skan// GNU General Public License for more details. 16132720Skan 17132720Skan// You should have received a copy of the GNU General Public License along 18132720Skan// with this library; see the file COPYING. If not, write to the Free 19169691Skan// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 20132720Skan// USA. 21132720Skan 22132720Skan// As a special exception, you may use this file as part of a free software 23132720Skan// library without restriction. Specifically, if other files instantiate 24132720Skan// templates or use macros or inline functions from this file, or you compile 25132720Skan// this file and link it with other files to produce an executable, this 26132720Skan// file does not by itself cause the resulting executable to be covered by 27132720Skan// the GNU General Public License. This exception does not however 28132720Skan// invalidate any other reasons why the executable file might be covered by 29132720Skan// the GNU General Public License. 30132720Skan 31169691Skan/** @file debug/debug.h 32169691Skan * This file is a GNU debug extension to the Standard C++ Library. 33132720Skan */ 34132720Skan 35169691Skan#ifndef _GLIBCXX_DEBUG_MACRO_SWITCH_H 36169691Skan#define _GLIBCXX_DEBUG_MACRO_SWITCH_H 1 37132720Skan 38169691Skan/** Macros and namespaces used by the implementation outside of debug 39169691Skan * wrappers to verify certain properties. The __glibcxx_requires_xxx 40169691Skan * macros are merely wrappers around the __glibcxx_check_xxx wrappers 41169691Skan * when we are compiling with debug mode, but disappear when we are 42169691Skan * in release mode so that there is no checking performed in, e.g., 43169691Skan * the standard library algorithms. 44132720Skan*/ 45132720Skan 46169691Skan// Debug mode namespaces. 47169691Skannamespace std 48169691Skan{ 49169691Skan namespace __debug { } 50169691Skan} 51132720Skan 52169691Skannamespace __gnu_cxx 53169691Skan{ 54169691Skan namespace __debug { }; 55169691Skan} 56132720Skan 57169691Skannamespace __gnu_debug 58169691Skan{ 59169691Skan using namespace std::__debug; 60169691Skan using namespace __gnu_cxx::__debug; 61169691Skan} 62132720Skan 63169691Skan#ifndef _GLIBCXX_DEBUG 64132720Skan 65169691Skan# define _GLIBCXX_DEBUG_ASSERT(_Condition) 66169691Skan# define _GLIBCXX_DEBUG_PEDASSERT(_Condition) 67169691Skan# define _GLIBCXX_DEBUG_ONLY(_Statement) ; 68169691Skan# define __glibcxx_requires_cond(_Cond,_Msg) 69169691Skan# define __glibcxx_requires_valid_range(_First,_Last) 70169691Skan# define __glibcxx_requires_sorted(_First,_Last) 71169691Skan# define __glibcxx_requires_sorted_pred(_First,_Last,_Pred) 72169691Skan# define __glibcxx_requires_partitioned(_First,_Last,_Value) 73169691Skan# define __glibcxx_requires_partitioned_pred(_First,_Last,_Value,_Pred) 74169691Skan# define __glibcxx_requires_heap(_First,_Last) 75169691Skan# define __glibcxx_requires_heap_pred(_First,_Last,_Pred) 76169691Skan# define __glibcxx_requires_nonempty() 77169691Skan# define __glibcxx_requires_string(_String) 78169691Skan# define __glibcxx_requires_string_len(_String,_Len) 79169691Skan# define __glibcxx_requires_subscript(_N) 80132720Skan 81169691Skan#else 82132720Skan 83169691Skan# include <cstdlib> 84169691Skan# include <cstdio> 85169691Skan# include <debug/macros.h> 86132720Skan 87169691Skannamespace std 88169691Skan{ 89169691Skan namespace __debug 90169691Skan { 91169691Skan // Avoid the use of assert, because we're trying to keep the <cassert> 92169691Skan // include out of the mix. 93169691Skan inline void 94169691Skan __replacement_assert(const char* __file, int __line, 95169691Skan const char* __function, const char* __condition) 96169691Skan { 97169691Skan printf("%s:%d: %s: Assertion '%s' failed.\n", __file, __line, 98169691Skan __function, __condition); 99169691Skan abort(); 100169691Skan } 101169691Skan } // namespace __debug 102169691Skan} // namespace std 103132720Skan 104169691Skan#define _GLIBCXX_DEBUG_ASSERT(_Condition) \ 105169691Skan do \ 106169691Skan { \ 107169691Skan if (! (_Condition)) \ 108169691Skan std::__debug::__replacement_assert(__FILE__, __LINE__, \ 109169691Skan __PRETTY_FUNCTION__, #_Condition); \ 110169691Skan } while (false) 111132720Skan 112132720Skan#ifdef _GLIBCXX_DEBUG_PEDANTIC 113169691Skan# define _GLIBCXX_DEBUG_PEDASSERT(_Condition) _GLIBCXX_DEBUG_ASSERT(_Condition) 114132720Skan#else 115169691Skan# define _GLIBCXX_DEBUG_PEDASSERT(_Condition) 116132720Skan#endif 117169691Skan# define _GLIBCXX_DEBUG_ONLY(_Statement) _Statement 118132720Skan 119169691Skan# define __glibcxx_requires_cond(_Cond,_Msg) _GLIBCXX_DEBUG_VERIFY(_Cond,_Msg) 120169691Skan# define __glibcxx_requires_valid_range(_First,_Last) \ 121132720Skan __glibcxx_check_valid_range(_First,_Last) 122169691Skan# define __glibcxx_requires_sorted(_First,_Last) \ 123132720Skan __glibcxx_check_sorted(_First,_Last) 124169691Skan# define __glibcxx_requires_sorted_pred(_First,_Last,_Pred) \ 125132720Skan __glibcxx_check_sorted_pred(_First,_Last,_Pred) 126169691Skan# define __glibcxx_requires_partitioned(_First,_Last,_Value) \ 127132720Skan __glibcxx_check_partitioned(_First,_Last,_Value) 128169691Skan# define __glibcxx_requires_partitioned_pred(_First,_Last,_Value,_Pred) \ 129132720Skan __glibcxx_check_partitioned_pred(_First,_Last,_Value,_Pred) 130169691Skan# define __glibcxx_requires_heap(_First,_Last) \ 131132720Skan __glibcxx_check_heap(_First,_Last) 132169691Skan# define __glibcxx_requires_heap_pred(_First,_Last,_Pred) \ 133132720Skan __glibcxx_check_heap_pred(_First,_Last,_Pred) 134169691Skan# define __glibcxx_requires_nonempty() __glibcxx_check_nonempty() 135169691Skan# define __glibcxx_requires_string(_String) __glibcxx_check_string(_String) 136169691Skan# define __glibcxx_requires_string_len(_String,_Len) \ 137132720Skan __glibcxx_check_string_len(_String,_Len) 138169691Skan# define __glibcxx_requires_subscript(_N) __glibcxx_check_subscript(_N) 139132720Skan 140169691Skan# include <debug/functions.h> 141169691Skan# include <debug/formatter.h> 142132720Skan 143132720Skan#endif 144132720Skan 145169691Skan#endif // _GLIBCXX_DEBUG_MACRO_SWITCH_H 146