libstdc++
|
00001 // Debugging support implementation -*- C++ -*- 00002 00003 // Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 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 3, 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 // Under Section 7 of GPL version 3, you are granted additional 00018 // permissions described in the GCC Runtime Library Exception, version 00019 // 3.1, as published by the Free Software Foundation. 00020 00021 // You should have received a copy of the GNU General Public License and 00022 // a copy of the GCC Runtime Library Exception along with this program; 00023 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00024 // <http://www.gnu.org/licenses/>. 00025 00026 /** @file debug/macros.h 00027 * This file is a GNU debug extension to the Standard C++ Library. 00028 */ 00029 00030 #ifndef _GLIBCXX_DEBUG_MACROS_H 00031 #define _GLIBCXX_DEBUG_MACROS_H 1 00032 00033 /** 00034 * Macros used by the implementation to verify certain 00035 * properties. These macros may only be used directly by the debug 00036 * wrappers. Note that these are macros (instead of the more obviously 00037 * "correct" choice of making them functions) because we need line and 00038 * file information at the call site, to minimize the distance between 00039 * the user error and where the error is reported. 00040 * 00041 */ 00042 #define _GLIBCXX_DEBUG_VERIFY(_Condition,_ErrorMessage) \ 00043 do \ 00044 { \ 00045 if (! (_Condition)) \ 00046 __gnu_debug::_Error_formatter::_M_at(__FILE__, __LINE__) \ 00047 ._ErrorMessage._M_error(); \ 00048 } while (false) 00049 00050 // Verify that [_First, _Last) forms a valid iterator range. 00051 #define __glibcxx_check_valid_range(_First,_Last) \ 00052 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__valid_range(_First, _Last), \ 00053 _M_message(__gnu_debug::__msg_valid_range) \ 00054 ._M_iterator(_First, #_First) \ 00055 ._M_iterator(_Last, #_Last)) 00056 00057 /** Verify that we can insert into *this with the iterator _Position. 00058 * Insertion into a container at a specific position requires that 00059 * the iterator be nonsingular (i.e., either dereferenceable or 00060 * past-the-end) and that it reference the sequence we are inserting 00061 * into. Note that this macro is only valid when the container is a 00062 * _Safe_sequence and the iterator is a _Safe_iterator. 00063 */ 00064 #define __glibcxx_check_insert(_Position) \ 00065 _GLIBCXX_DEBUG_VERIFY(!_Position._M_singular(), \ 00066 _M_message(__gnu_debug::__msg_insert_singular) \ 00067 ._M_sequence(*this, "this") \ 00068 ._M_iterator(_Position, #_Position)); \ 00069 _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \ 00070 _M_message(__gnu_debug::__msg_insert_different) \ 00071 ._M_sequence(*this, "this") \ 00072 ._M_iterator(_Position, #_Position)) 00073 00074 /** Verify that we can insert the values in the iterator range 00075 * [_First, _Last) into *this with the iterator _Position. Insertion 00076 * into a container at a specific position requires that the iterator 00077 * be nonsingular (i.e., either dereferenceable or past-the-end), 00078 * that it reference the sequence we are inserting into, and that the 00079 * iterator range [_First, Last) is a valid (possibly empty) 00080 * range. Note that this macro is only valid when the container is a 00081 * _Safe_sequence and the iterator is a _Safe_iterator. 00082 * 00083 * @tbd We would like to be able to check for noninterference of 00084 * _Position and the range [_First, _Last), but that can't (in 00085 * general) be done. 00086 */ 00087 #define __glibcxx_check_insert_range(_Position,_First,_Last) \ 00088 __glibcxx_check_valid_range(_First,_Last); \ 00089 _GLIBCXX_DEBUG_VERIFY(!_Position._M_singular(), \ 00090 _M_message(__gnu_debug::__msg_insert_singular) \ 00091 ._M_sequence(*this, "this") \ 00092 ._M_iterator(_Position, #_Position)); \ 00093 _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \ 00094 _M_message(__gnu_debug::__msg_insert_different) \ 00095 ._M_sequence(*this, "this") \ 00096 ._M_iterator(_Position, #_Position)) 00097 00098 /** Verify that we can erase the element referenced by the iterator 00099 * _Position. We can erase the element if the _Position iterator is 00100 * dereferenceable and references this sequence. 00101 */ 00102 #define __glibcxx_check_erase(_Position) \ 00103 _GLIBCXX_DEBUG_VERIFY(_Position._M_dereferenceable(), \ 00104 _M_message(__gnu_debug::__msg_erase_bad) \ 00105 ._M_sequence(*this, "this") \ 00106 ._M_iterator(_Position, #_Position)); \ 00107 _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \ 00108 _M_message(__gnu_debug::__msg_erase_different) \ 00109 ._M_sequence(*this, "this") \ 00110 ._M_iterator(_Position, #_Position)) 00111 00112 /** Verify that we can erase the elements in the iterator range 00113 * [_First, _Last). We can erase the elements if [_First, _Last) is a 00114 * valid iterator range within this sequence. 00115 */ 00116 #define __glibcxx_check_erase_range(_First,_Last) \ 00117 __glibcxx_check_valid_range(_First,_Last); \ 00118 _GLIBCXX_DEBUG_VERIFY(_First._M_attached_to(this), \ 00119 _M_message(__gnu_debug::__msg_erase_different) \ 00120 ._M_sequence(*this, "this") \ 00121 ._M_iterator(_First, #_First) \ 00122 ._M_iterator(_Last, #_Last)) 00123 00124 // Verify that the subscript _N is less than the container's size. 00125 #define __glibcxx_check_subscript(_N) \ 00126 _GLIBCXX_DEBUG_VERIFY(_N < this->size(), \ 00127 _M_message(__gnu_debug::__msg_subscript_oob) \ 00128 ._M_sequence(*this, "this") \ 00129 ._M_integer(_N, #_N) \ 00130 ._M_integer(this->size(), "size")) 00131 00132 // Verify that the container is nonempty 00133 #define __glibcxx_check_nonempty() \ 00134 _GLIBCXX_DEBUG_VERIFY(! this->empty(), \ 00135 _M_message(__gnu_debug::__msg_empty) \ 00136 ._M_sequence(*this, "this")) 00137 00138 // Verify that the iterator range [_First, _Last) is sorted 00139 #define __glibcxx_check_sorted(_First,_Last) \ 00140 __glibcxx_check_valid_range(_First,_Last); \ 00141 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted(_First, _Last), \ 00142 _M_message(__gnu_debug::__msg_unsorted) \ 00143 ._M_iterator(_First, #_First) \ 00144 ._M_iterator(_Last, #_Last)) 00145 00146 /** Verify that the iterator range [_First, _Last) is sorted by the 00147 predicate _Pred. */ 00148 #define __glibcxx_check_sorted_pred(_First,_Last,_Pred) \ 00149 __glibcxx_check_valid_range(_First,_Last); \ 00150 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted(_First, _Last, _Pred), \ 00151 _M_message(__gnu_debug::__msg_unsorted_pred) \ 00152 ._M_iterator(_First, #_First) \ 00153 ._M_iterator(_Last, #_Last) \ 00154 ._M_string(#_Pred)) 00155 00156 // Special variant for std::merge, std::includes, std::set_* 00157 #define __glibcxx_check_sorted_set(_First1,_Last1,_First2) \ 00158 __glibcxx_check_valid_range(_First1,_Last1); \ 00159 _GLIBCXX_DEBUG_VERIFY( \ 00160 __gnu_debug::__check_sorted_set(_First1, _Last1, _First2), \ 00161 _M_message(__gnu_debug::__msg_unsorted) \ 00162 ._M_iterator(_First1, #_First1) \ 00163 ._M_iterator(_Last1, #_Last1)) 00164 00165 // Likewise with a _Pred. 00166 #define __glibcxx_check_sorted_set_pred(_First1,_Last1,_First2,_Pred) \ 00167 __glibcxx_check_valid_range(_First1,_Last1); \ 00168 _GLIBCXX_DEBUG_VERIFY( \ 00169 __gnu_debug::__check_sorted_set(_First1, _Last1, _First2, _Pred), \ 00170 _M_message(__gnu_debug::__msg_unsorted_pred) \ 00171 ._M_iterator(_First1, #_First1) \ 00172 ._M_iterator(_Last1, #_Last1) \ 00173 ._M_string(#_Pred)) 00174 00175 /** Verify that the iterator range [_First, _Last) is partitioned 00176 w.r.t. the value _Value. */ 00177 #define __glibcxx_check_partitioned_lower(_First,_Last,_Value) \ 00178 __glibcxx_check_valid_range(_First,_Last); \ 00179 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_lower(_First, _Last, \ 00180 _Value), \ 00181 _M_message(__gnu_debug::__msg_unpartitioned) \ 00182 ._M_iterator(_First, #_First) \ 00183 ._M_iterator(_Last, #_Last) \ 00184 ._M_string(#_Value)) 00185 00186 #define __glibcxx_check_partitioned_upper(_First,_Last,_Value) \ 00187 __glibcxx_check_valid_range(_First,_Last); \ 00188 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_upper(_First, _Last, \ 00189 _Value), \ 00190 _M_message(__gnu_debug::__msg_unpartitioned) \ 00191 ._M_iterator(_First, #_First) \ 00192 ._M_iterator(_Last, #_Last) \ 00193 ._M_string(#_Value)) 00194 00195 /** Verify that the iterator range [_First, _Last) is partitioned 00196 w.r.t. the value _Value and predicate _Pred. */ 00197 #define __glibcxx_check_partitioned_lower_pred(_First,_Last,_Value,_Pred) \ 00198 __glibcxx_check_valid_range(_First,_Last); \ 00199 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_lower(_First, _Last, \ 00200 _Value, _Pred), \ 00201 _M_message(__gnu_debug::__msg_unpartitioned_pred) \ 00202 ._M_iterator(_First, #_First) \ 00203 ._M_iterator(_Last, #_Last) \ 00204 ._M_string(#_Pred) \ 00205 ._M_string(#_Value)) 00206 00207 /** Verify that the iterator range [_First, _Last) is partitioned 00208 w.r.t. the value _Value and predicate _Pred. */ 00209 #define __glibcxx_check_partitioned_upper_pred(_First,_Last,_Value,_Pred) \ 00210 __glibcxx_check_valid_range(_First,_Last); \ 00211 _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_upper(_First, _Last, \ 00212 _Value, _Pred), \ 00213 _M_message(__gnu_debug::__msg_unpartitioned_pred) \ 00214 ._M_iterator(_First, #_First) \ 00215 ._M_iterator(_Last, #_Last) \ 00216 ._M_string(#_Pred) \ 00217 ._M_string(#_Value)) 00218 00219 // Verify that the iterator range [_First, _Last) is a heap 00220 #define __glibcxx_check_heap(_First,_Last) \ 00221 __glibcxx_check_valid_range(_First,_Last); \ 00222 _GLIBCXX_DEBUG_VERIFY(std::__is_heap(_First, _Last), \ 00223 _M_message(__gnu_debug::__msg_not_heap) \ 00224 ._M_iterator(_First, #_First) \ 00225 ._M_iterator(_Last, #_Last)) 00226 00227 /** Verify that the iterator range [_First, _Last) is a heap 00228 w.r.t. the predicate _Pred. */ 00229 #define __glibcxx_check_heap_pred(_First,_Last,_Pred) \ 00230 __glibcxx_check_valid_range(_First,_Last); \ 00231 _GLIBCXX_DEBUG_VERIFY(std::__is_heap(_First, _Last, _Pred), \ 00232 _M_message(__gnu_debug::__msg_not_heap_pred) \ 00233 ._M_iterator(_First, #_First) \ 00234 ._M_iterator(_Last, #_Last) \ 00235 ._M_string(#_Pred)) 00236 00237 #ifdef _GLIBCXX_DEBUG_PEDANTIC 00238 # define __glibcxx_check_string(_String) _GLIBCXX_DEBUG_ASSERT(_String != 0) 00239 # define __glibcxx_check_string_len(_String,_Len) \ 00240 _GLIBCXX_DEBUG_ASSERT(_String != 0 || _Len == 0) 00241 #else 00242 # define __glibcxx_check_string(_String) 00243 # define __glibcxx_check_string_len(_String,_Len) 00244 #endif 00245 00246 #endif