2 //===--------------------------- __debug ----------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_DEBUG_H
12 #define _LIBCPP_DEBUG_H
16 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17 #pragma GCC system_header
20 #if defined(_LIBCPP_HAS_NO_NULLPTR)
24 #if _LIBCPP_DEBUG_LEVEL >= 1 || defined(_LIBCPP_BUILDING_LIBRARY)
31 #if _LIBCPP_DEBUG_LEVEL >= 1 && !defined(_LIBCPP_ASSERT)
32 # define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : \
33 _VSTD::__libcpp_debug_function(_VSTD::__libcpp_debug_info(__FILE__, __LINE__, #x, m)))
36 #if _LIBCPP_DEBUG_LEVEL >= 2
37 #ifndef _LIBCPP_DEBUG_ASSERT
38 #define _LIBCPP_DEBUG_ASSERT(x, m) _LIBCPP_ASSERT(x, m)
40 #define _LIBCPP_DEBUG_MODE(...) __VA_ARGS__
43 #ifndef _LIBCPP_ASSERT
44 # define _LIBCPP_ASSERT(x, m) ((void)0)
46 #ifndef _LIBCPP_DEBUG_ASSERT
47 # define _LIBCPP_DEBUG_ASSERT(x, m) ((void)0)
49 #ifndef _LIBCPP_DEBUG_MODE
50 #define _LIBCPP_DEBUG_MODE(...) ((void)0)
53 #if _LIBCPP_DEBUG_LEVEL < 1
54 class _LIBCPP_EXCEPTION_ABI __libcpp_debug_exception;
57 _LIBCPP_BEGIN_NAMESPACE_STD
59 struct _LIBCPP_TEMPLATE_VIS __libcpp_debug_info {
60 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
62 : __file_(nullptr), __line_(-1), __pred_(nullptr), __msg_(nullptr) {}
63 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
64 __libcpp_debug_info(const char* __f, int __l, const char* __p, const char* __m)
65 : __file_(__f), __line_(__l), __pred_(__p), __msg_(__m) {}
72 /// __libcpp_debug_function_type - The type of the assertion failure handler.
73 typedef void(*__libcpp_debug_function_type)(__libcpp_debug_info const&);
75 /// __libcpp_debug_function - The handler function called when a _LIBCPP_ASSERT
77 extern _LIBCPP_EXTERN_VIS __libcpp_debug_function_type __libcpp_debug_function;
79 /// __libcpp_abort_debug_function - A debug handler that aborts when called.
80 _LIBCPP_NORETURN _LIBCPP_FUNC_VIS
81 void __libcpp_abort_debug_function(__libcpp_debug_info const&);
83 /// __libcpp_throw_debug_function - A debug handler that throws
84 /// an instance of __libcpp_debug_exception when called.
85 _LIBCPP_NORETURN _LIBCPP_FUNC_VIS
86 void __libcpp_throw_debug_function(__libcpp_debug_info const&);
88 /// __libcpp_set_debug_function - Set the debug handler to the specified
91 bool __libcpp_set_debug_function(__libcpp_debug_function_type __func);
93 // Setup the throwing debug handler during dynamic initialization.
94 #if _LIBCPP_DEBUG_LEVEL >= 1 && defined(_LIBCPP_DEBUG_USE_EXCEPTIONS)
95 # if defined(_LIBCPP_NO_EXCEPTIONS)
96 # error _LIBCPP_DEBUG_USE_EXCEPTIONS cannot be used when exceptions are disabled.
98 static bool __init_dummy = __libcpp_set_debug_function(__libcpp_throw_debug_function);
101 #if _LIBCPP_DEBUG_LEVEL >= 1 || defined(_LIBCPP_BUILDING_LIBRARY)
102 class _LIBCPP_EXCEPTION_ABI __libcpp_debug_exception : public exception {
104 __libcpp_debug_exception() _NOEXCEPT;
105 explicit __libcpp_debug_exception(__libcpp_debug_info const& __i);
106 __libcpp_debug_exception(__libcpp_debug_exception const&);
107 ~__libcpp_debug_exception() _NOEXCEPT;
108 const char* what() const _NOEXCEPT;
110 struct __libcpp_debug_exception_imp;
111 __libcpp_debug_exception_imp *__imp_;
115 #if _LIBCPP_DEBUG_LEVEL >= 2 || defined(_LIBCPP_BUILDING_LIBRARY)
117 struct _LIBCPP_TYPE_VIS __c_node;
119 struct _LIBCPP_TYPE_VIS __i_node
125 #ifndef _LIBCPP_CXX03_LANG
126 __i_node(const __i_node&) = delete;
127 __i_node& operator=(const __i_node&) = delete;
130 __i_node(const __i_node&);
131 __i_node& operator=(const __i_node&);
134 _LIBCPP_INLINE_VISIBILITY
135 __i_node(void* __i, __i_node* __next, __c_node* __c)
136 : __i_(__i), __next_(__next), __c_(__c) {}
140 struct _LIBCPP_TYPE_VIS __c_node
148 #ifndef _LIBCPP_CXX03_LANG
149 __c_node(const __c_node&) = delete;
150 __c_node& operator=(const __c_node&) = delete;
153 __c_node(const __c_node&);
154 __c_node& operator=(const __c_node&);
157 _LIBCPP_INLINE_VISIBILITY
158 __c_node(void* __c, __c_node* __next)
159 : __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {}
162 virtual bool __dereferenceable(const void*) const = 0;
163 virtual bool __decrementable(const void*) const = 0;
164 virtual bool __addable(const void*, ptrdiff_t) const = 0;
165 virtual bool __subscriptable(const void*, ptrdiff_t) const = 0;
167 void __add(__i_node* __i);
168 _LIBCPP_HIDDEN void __remove(__i_node* __i);
171 template <class _Cont>
175 _C_node(void* __c, __c_node* __n)
176 : __c_node(__c, __n) {}
178 virtual bool __dereferenceable(const void*) const;
179 virtual bool __decrementable(const void*) const;
180 virtual bool __addable(const void*, ptrdiff_t) const;
181 virtual bool __subscriptable(const void*, ptrdiff_t) const;
184 template <class _Cont>
186 _C_node<_Cont>::__dereferenceable(const void* __i) const
188 typedef typename _Cont::const_iterator iterator;
189 const iterator* __j = static_cast<const iterator*>(__i);
190 _Cont* _Cp = static_cast<_Cont*>(__c_);
191 return _Cp->__dereferenceable(__j);
194 template <class _Cont>
196 _C_node<_Cont>::__decrementable(const void* __i) const
198 typedef typename _Cont::const_iterator iterator;
199 const iterator* __j = static_cast<const iterator*>(__i);
200 _Cont* _Cp = static_cast<_Cont*>(__c_);
201 return _Cp->__decrementable(__j);
204 template <class _Cont>
206 _C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const
208 typedef typename _Cont::const_iterator iterator;
209 const iterator* __j = static_cast<const iterator*>(__i);
210 _Cont* _Cp = static_cast<_Cont*>(__c_);
211 return _Cp->__addable(__j, __n);
214 template <class _Cont>
216 _C_node<_Cont>::__subscriptable(const void* __i, ptrdiff_t __n) const
218 typedef typename _Cont::const_iterator iterator;
219 const iterator* __j = static_cast<const iterator*>(__i);
220 _Cont* _Cp = static_cast<_Cont*>(__c_);
221 return _Cp->__subscriptable(__j, __n);
224 class _LIBCPP_TYPE_VIS __libcpp_db
235 #ifndef _LIBCPP_CXX03_LANG
236 __libcpp_db(const __libcpp_db&) = delete;
237 __libcpp_db& operator=(const __libcpp_db&) = delete;
240 __libcpp_db(const __libcpp_db&);
241 __libcpp_db& operator=(const __libcpp_db&);
246 class __db_c_iterator;
247 class __db_c_const_iterator;
248 class __db_i_iterator;
249 class __db_i_const_iterator;
251 __db_c_const_iterator __c_end() const;
252 __db_i_const_iterator __i_end() const;
254 template <class _Cont>
255 _LIBCPP_INLINE_VISIBILITY
256 void __insert_c(_Cont* __c)
258 __c_node* __n = __insert_c(static_cast<void*>(__c));
259 ::new(__n) _C_node<_Cont>(__n->__c_, __n->__next_);
262 void __insert_i(void* __i);
263 __c_node* __insert_c(void* __c);
264 void __erase_c(void* __c);
266 void __insert_ic(void* __i, const void* __c);
267 void __iterator_copy(void* __i, const void* __i0);
268 void __erase_i(void* __i);
270 void* __find_c_from_i(void* __i) const;
271 void __invalidate_all(void* __c);
272 __c_node* __find_c_and_lock(void* __c) const;
273 __c_node* __find_c(void* __c) const;
276 void swap(void* __c1, void* __c2);
279 bool __dereferenceable(const void* __i) const;
280 bool __decrementable(const void* __i) const;
281 bool __addable(const void* __i, ptrdiff_t __n) const;
282 bool __subscriptable(const void* __i, ptrdiff_t __n) const;
283 bool __less_than_comparable(const void* __i, const void* __j) const;
286 __i_node* __insert_iterator(void* __i);
288 __i_node* __find_iterator(const void* __i) const;
290 friend _LIBCPP_FUNC_VIS __libcpp_db* __get_db();
293 _LIBCPP_FUNC_VIS __libcpp_db* __get_db();
294 _LIBCPP_FUNC_VIS const __libcpp_db* __get_const_db();
297 #endif // _LIBCPP_DEBUG_LEVEL >= 2 || defined(_LIBCPP_BUILDING_LIBRARY)
299 _LIBCPP_END_NAMESPACE_STD
301 #endif // _LIBCPP_DEBUG_H