[cfe-commits] [libcxx] r139913 - in /libcxx/trunk: include/__config include/__debug include/iterator include/vector src/debug.cpp
Howard Hinnant
hhinnant at apple.com
Fri Sep 16 10:29:17 PDT 2011
Author: hhinnant
Date: Fri Sep 16 12:29:17 2011
New Revision: 139913
URL: http://llvm.org/viewvc/llvm-project?rev=139913&view=rev
Log:
Create multilevel debug mode
Modified:
libcxx/trunk/include/__config
libcxx/trunk/include/__debug
libcxx/trunk/include/iterator
libcxx/trunk/include/vector
libcxx/trunk/src/debug.cpp
Modified: libcxx/trunk/include/__config
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=139913&r1=139912&r2=139913&view=diff
==============================================================================
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Fri Sep 16 12:29:17 2011
@@ -310,6 +310,16 @@
#endif
#ifdef _LIBCPP_DEBUG2
+# if _LIBCPP_DEBUG2 == 0
+# define _LIBCPP_DEBUG_LEVEL 1
+# elif _LIBCPP_DEBUG2 == 1
+# define _LIBCPP_DEBUG_LEVEL 2
+# else
+# error Supported values for _LIBCPP_DEBUG2 are 0 and 1
+# endif
+#endif
+
+#ifdef _LIBCPP_DEBUG2
# include <__debug>
#else
# define _LIBCPP_ASSERT(x, m) ((void)0)
Modified: libcxx/trunk/include/__debug
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__debug?rev=139913&r1=139912&r2=139913&view=diff
==============================================================================
--- libcxx/trunk/include/__debug (original)
+++ libcxx/trunk/include/__debug Fri Sep 16 12:29:17 2011
@@ -11,11 +11,17 @@
#ifndef _LIBCPP_DEBUG_H
#define _LIBCPP_DEBUG_H
+#if _LIBCPP_DEBUG_LEVEL >= 1
+
# include <cstdlib>
# include <cstdio>
# include <cstddef>
# define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : (_VSTD::printf("%s\n", m), _VSTD::abort()))
+#endif
+
+#if _LIBCPP_DEBUG_LEVEL >= 2
+
_LIBCPP_BEGIN_NAMESPACE_STD
struct _LIBCPP_VISIBLE __c_node;
@@ -177,5 +183,7 @@
_LIBCPP_END_NAMESPACE_STD
+#endif
+
#endif // _LIBCPP_DEBUG_H
Modified: libcxx/trunk/include/iterator
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/iterator?rev=139913&r1=139912&r2=139913&view=diff
==============================================================================
--- libcxx/trunk/include/iterator (original)
+++ libcxx/trunk/include/iterator Fri Sep 16 12:29:17 2011
@@ -1068,11 +1068,11 @@
typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT
: __i(__u.base())
{
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__iterator_copy(this, &__u);
#endif
}
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY
__wrap_iter(const __wrap_iter& __x)
: __i(__x.base())
@@ -1097,15 +1097,19 @@
#endif
_LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT
{
+#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to dereference a non-dereferenceable iterator");
+#endif
return *__i;
}
_LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return &(operator*());}
_LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT
{
+#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to increment non-incrementable iterator");
+#endif
++__i;
return *this;
}
@@ -1113,8 +1117,10 @@
{__wrap_iter __tmp(*this); ++(*this); return __tmp;}
_LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT
{
+#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
"Attempted to decrement non-decrementable iterator");
+#endif
--__i;
return *this;
}
@@ -1124,8 +1130,10 @@
{__wrap_iter __w(*this); __w += __n; return __w;}
_LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
{
+#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
"Attempted to add/subtract iterator outside of valid range");
+#endif
__i += __n;
return *this;
}
@@ -1135,8 +1143,10 @@
{*this += -__n; return *this;}
_LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT
{
+#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
"Attempted to subscript iterator outside of valid range");
+#endif
return __i[__n];
}
@@ -1144,7 +1154,7 @@
private:
_LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
{
__get_db()->__insert_ic(this, __p);
@@ -1215,8 +1225,10 @@
bool
operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
{
+#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y),
"Attempted to compare incomparable iterators");
+#endif
return __x.base() == __y.base();
}
@@ -1225,8 +1237,10 @@
bool
operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
{
+#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y),
"Attempted to compare incomparable iterators");
+#endif
return __x.base() < __y.base();
}
@@ -1267,8 +1281,10 @@
typename __wrap_iter<_Iter1>::difference_type
operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
{
+#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y),
"Attempted to subtract incompatible iterators");
+#endif
return __x.base() - __y.base();
}
Modified: libcxx/trunk/include/vector
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/vector?rev=139913&r1=139912&r2=139913&view=diff
==============================================================================
--- libcxx/trunk/include/vector (original)
+++ libcxx/trunk/include/vector Fri Sep 16 12:29:17 2011
@@ -269,9 +269,6 @@
#include <cstring>
#include <__split_buffer>
#include <__functional_base>
-#if defined(_LIBCPP_DEBUG) || defined(_LIBCPP_NO_EXCEPTIONS)
- #include <cassert>
-#endif
#pragma GCC system_header
@@ -489,24 +486,8 @@
typedef typename __base::difference_type difference_type;
typedef typename __base::pointer pointer;
typedef typename __base::const_pointer const_pointer;
-#ifdef _LIBCPP_DEBUG
- typedef __debug_iter<vector, pointer> iterator;
- typedef __debug_iter<vector, const_pointer> const_iterator;
-
- friend class __debug_iter<vector, pointer>;
- friend class __debug_iter<vector, const_pointer>;
-
- pair<iterator*, const_iterator*> __iterator_list_;
-
- _LIBCPP_INLINE_VISIBILITY iterator*& __get_iterator_list(iterator*) {return __iterator_list_.first;}
- _LIBCPP_INLINE_VISIBILITY const_iterator*& __get_iterator_list(const_iterator*) {return __iterator_list_.second;}
-#elif defined(_LIBCPP_RAW_ITERATORS)
- typedef pointer iterator;
- typedef const_pointer const_iterator;
-#else // defined(_LIBCPP_RAW_ITERATORS)
typedef __wrap_iter<pointer> iterator;
typedef __wrap_iter<const_pointer> const_iterator;
-#endif // defined(_LIBCPP_RAW_ITERATORS)
typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
@@ -514,14 +495,14 @@
vector()
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
{
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
_LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
: __base(__a)
{
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
@@ -548,7 +529,7 @@
_LIBCPP_INLINE_VISIBILITY
vector(initializer_list<value_type> __il, const allocator_type& __a);
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY
~vector()
{
@@ -741,14 +722,14 @@
bool __invariants() const;
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
bool __dereferenceable(const const_iterator* __i) const;
bool __decrementable(const const_iterator* __i) const;
bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
-#endif // _LIBCPP_DEBUG2
+#endif // _LIBCPP_DEBUG_LEVEL >= 2
private:
_LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
@@ -780,7 +761,7 @@
_LIBCPP_INLINE_VISIBILITY
void __destruct_at_end(const_pointer __new_last) _NOEXCEPT
{
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
__c_node* __c = __get_db()->__find_c_and_lock(this);
for (__i_node** __p = __c->end_; __p != __c->beg_; )
{
@@ -994,7 +975,7 @@
allocate(__n);
__construct_at_end(__n);
}
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
@@ -1007,7 +988,7 @@
allocate(__n);
__construct_at_end(__n, __x);
}
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
@@ -1021,7 +1002,7 @@
allocate(__n);
__construct_at_end(__n, __x);
}
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
@@ -1034,7 +1015,7 @@
{
for (; __first != __last; ++__first)
push_back(*__first);
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
@@ -1048,7 +1029,7 @@
{
for (; __first != __last; ++__first)
push_back(*__first);
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
@@ -1064,7 +1045,7 @@
allocate(__n);
__construct_at_end(__first, __last);
}
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
@@ -1081,7 +1062,7 @@
allocate(__n);
__construct_at_end(__first, __last);
}
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
@@ -1096,7 +1077,7 @@
allocate(__n);
__construct_at_end(__x.__begin_, __x.__end_);
}
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
@@ -1111,7 +1092,7 @@
allocate(__n);
__construct_at_end(__x.__begin_, __x.__end_);
}
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
@@ -1128,7 +1109,7 @@
this->__end_ = __x.__end_;
this->__end_cap() = __x.__end_cap();
__x.__begin_ = __x.__end_ = __x.__end_cap() = 0;
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
__x.__invalidate_all_iterators();
__get_db()->__insert_c(this);
#endif
@@ -1152,7 +1133,7 @@
typedef move_iterator<iterator> _I;
assign(_I(__x.begin()), _I(__x.end()));
}
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
@@ -1168,7 +1149,7 @@
allocate(__il.size());
__construct_at_end(__il.begin(), __il.end());
}
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
@@ -1183,7 +1164,7 @@
allocate(__il.size());
__construct_at_end(__il.begin(), __il.end());
}
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
@@ -1319,7 +1300,7 @@
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
{
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
return iterator(this, __p);
#else
return iterator(__p);
@@ -1331,7 +1312,7 @@
typename vector<_Tp, _Allocator>::const_iterator
vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
{
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
return const_iterator(this, __p);
#else
return const_iterator(__p);
@@ -1521,9 +1502,11 @@
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::erase(const_iterator __position)
{
+#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
"vector::erase(iterator) called with an iterator not"
" referring to this vector");
+#endif
pointer __p = const_cast<pointer>(&*__position);
iterator __r = __make_iter(__p);
this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
@@ -1534,9 +1517,11 @@
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
{
+#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
"vector::erase(iterator, iterator) called with an iterator not"
" referring to this vector");
+#endif
_LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
pointer __p = this->__begin_ + (__first - begin());
iterator __r = __make_iter(__p);
@@ -1561,9 +1546,11 @@
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
{
+#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
"vector::insert(iterator, x) called with an iterator not"
" referring to this vector");
+#endif
pointer __p = this->__begin_ + (__position - begin());
if (this->__end_ < this->__end_cap())
{
@@ -1598,9 +1585,11 @@
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
{
+#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
"vector::insert(iterator, x) called with an iterator not"
" referring to this vector");
+#endif
pointer __p = this->__begin_ + (__position - begin());
if (this->__end_ < this->__end_cap())
{
@@ -1634,9 +1623,11 @@
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
{
+#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
"vector::emplace(iterator, x) called with an iterator not"
" referring to this vector");
+#endif
pointer __p = this->__begin_ + (__position - begin());
if (this->__end_ < this->__end_cap())
{
@@ -1670,9 +1661,11 @@
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
{
+#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
"vector::insert(iterator, n, x) called with an iterator not"
" referring to this vector");
+#endif
pointer __p = this->__begin_ + (__position - begin());
if (__n > 0)
{
@@ -1716,9 +1709,11 @@
>::type
vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
{
+#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
"vector::insert(iterator, range) called with an iterator not"
" referring to this vector");
+#endif
difference_type __off = __position - begin();
pointer __p = this->__begin_ + __off;
allocator_type& __a = this->__alloc();
@@ -1766,9 +1761,11 @@
>::type
vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
{
+#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
"vector::insert(iterator, range) called with an iterator not"
" referring to this vector");
+#endif
pointer __p = this->__begin_ + (__position - begin());
difference_type __n = _VSTD::distance(__first, __last);
if (__n > 0)
@@ -1839,9 +1836,9 @@
_VSTD::swap(this->__end_, __x.__end_);
_VSTD::swap(this->__end_cap(), __x.__end_cap());
__base::__swap_alloc(this->__alloc(), __x.__alloc());
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->swap(this, &__x);
-#endif // _LIBCPP_DEBUG
+#endif // _LIBCPP_DEBUG_LEVEL >= 2
}
template <class _Tp, class _Allocator>
@@ -1865,7 +1862,7 @@
return true;
}
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
template <class _Tp, class _Allocator>
bool
@@ -1897,18 +1894,16 @@
return this->__begin_ <= __p && __p < this->__end_;
}
-#endif // LIBCPP_DEBUG2
+#endif // _LIBCPP_DEBUG_LEVEL >= 2
template <class _Tp, class _Allocator>
_LIBCPP_INLINE_VISIBILITY inline
void
vector<_Tp, _Allocator>::__invalidate_all_iterators()
{
-#ifdef _LIBCPP_DEBUG2
+#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__invalidate_all(this);
-// iterator::__remove_all(this);
-// const_iterator::__remove_all(this);
-#endif // _LIBCPP_DEBUG
+#endif // _LIBCPP_DEBUG_LEVEL >= 2
}
// vector<bool>
Modified: libcxx/trunk/src/debug.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/debug.cpp?rev=139913&r1=139912&r2=139913&view=diff
==============================================================================
--- libcxx/trunk/src/debug.cpp (original)
+++ libcxx/trunk/src/debug.cpp Fri Sep 16 12:29:17 2011
@@ -7,7 +7,8 @@
//
//===----------------------------------------------------------------------===//
-#define _LIBCPP_DEBUG2
+#define _LIBCPP_DEBUG2 1
+#include "__config"
#include "__debug"
#include "functional"
#include "algorithm"
@@ -35,11 +36,6 @@
{
typedef mutex mutex_type;
-// struct mutex_type
-// {
-// void lock() {}
-// void unlock() {};
-// };
typedef lock_guard<mutex_type> WLock;
typedef lock_guard<mutex_type> RLock;
More information about the cfe-commits
mailing list