Another installment on debug mode.  This addresses list.  However this should be considered a temporary state.  The API of the debug database and how vector and list use it, is unsatisfactory at the moment.  It is both inefficient and overly verbose.  I wanted to get this functionality checked in though.  In the next day or so I'll refactor what is there in an attempt to streamline things.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@140660 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/src/debug.cpp b/src/debug.cpp
index 2d2d643..8b660f5 100644
--- a/src/debug.cpp
+++ b/src/debug.cpp
@@ -120,20 +120,18 @@
 {
     WLock _(mut());
     __i_node* i = __insert_iterator(__i);
-    _LIBCPP_ASSERT(__cbeg_ != __cend_, "Container constructed in a translation unit with debug mode disabled."
-                   " But it is being used in a translation unit with debug mode enabled."
-                   " Enable it in the other translation unit with #define _LIBCPP_DEBUG2 1");
+    const char* errmsg =
+        "Container constructed in a translation unit with debug mode disabled."
+        " But it is being used in a translation unit with debug mode enabled."
+        " Enable it in the other translation unit with #define _LIBCPP_DEBUG2 1";
+    _LIBCPP_ASSERT(__cbeg_ != __cend_, errmsg);
     size_t hc = hash<const void*>()(__c) % (__cend_ - __cbeg_);
     __c_node* c = __cbeg_[hc];
-    _LIBCPP_ASSERT(c != nullptr, "Container constructed in a translation unit with debug mode disabled."
-                   " But it is being used in a translation unit with debug mode enabled."
-                   " Enable it in the other translation unit with #define _LIBCPP_DEBUG2 1");
+    _LIBCPP_ASSERT(c != nullptr, errmsg);
     while (c->__c_ != __c)
     {
         c = c->__next_;
-        _LIBCPP_ASSERT(c != nullptr, "Container constructed in a translation unit with debug mode disabled."
-                   " But it is being used in a translation unit with debug mode enabled."
-                   " Enable it in the other translation unit with #define _LIBCPP_DEBUG2 1");
+        _LIBCPP_ASSERT(c != nullptr, errmsg);
     }
     c->__add(i);
     i->__c_ = c;
@@ -241,6 +239,20 @@
     return p;
 }
 
+__c_node*
+__libcpp_db::__find_c(void* __c) const
+{
+    size_t hc = hash<void*>()(__c) % (__cend_ - __cbeg_);
+    __c_node* p = __cbeg_[hc];
+    _LIBCPP_ASSERT(p != nullptr, "debug mode internal logic error __find_c A");
+    while (p->__c_ != __c)
+    {
+        p = p->__next_;
+        _LIBCPP_ASSERT(p != nullptr, "debug mode internal logic error __find_c B");
+    }
+    return p;
+}
+
 void
 __libcpp_db::unlock() const
 {
@@ -380,6 +392,27 @@
     __insert_iterator(__i);
 }
 
+void
+__c_node::__add(__i_node* i)
+{
+    if (end_ == cap_)
+    {
+        size_t nc = 2*(cap_ - beg_);
+        if (nc == 0)
+            nc = 1;
+        __i_node** beg = (__i_node**)malloc(nc * sizeof(__i_node*));
+        if (beg == nullptr)
+            throw bad_alloc();
+        if (nc > 1)
+            memcpy(beg, beg_, nc/2*sizeof(__i_node*));
+        free(beg_);
+        beg_ = beg;
+        end_ = beg_ + nc/2;
+        cap_ = beg_ + nc;
+    }
+    *end_++ = i;
+}
+
 // private api
 
 _LIBCPP_HIDDEN
@@ -440,28 +473,6 @@
 
 _LIBCPP_HIDDEN
 void
-__c_node::__add(__i_node* i)
-{
-    if (end_ == cap_)
-    {
-        size_t nc = 2*(cap_ - beg_);
-        if (nc == 0)
-            nc = 1;
-        __i_node** beg = (__i_node**)malloc(nc * sizeof(__i_node*));
-        if (beg == nullptr)
-            throw bad_alloc();
-        if (nc > 1)
-            memcpy(beg, beg_, nc/2*sizeof(__i_node*));
-        free(beg_);
-        beg_ = beg;
-        end_ = beg_ + nc/2;
-        cap_ = beg_ + nc;
-    }
-    *end_++ = i;
-}
-
-_LIBCPP_HIDDEN
-void
 __c_node::__remove(__i_node* p)
 {
     __i_node** r = find(beg_, end_, p);