formatter.h (_Error_formatter::_M_function): New.
authorFrançois Dumont <fdumont@gcc.gnu.org>
Tue, 8 May 2018 19:41:02 +0000 (19:41 +0000)
committerFrançois Dumont <fdumont@gcc.gnu.org>
Tue, 8 May 2018 19:41:02 +0000 (19:41 +0000)
2018-05-08  François Dumont  <fdumont@gcc.gnu.org>

* include/debug/formatter.h (_Error_formatter::_M_function): New.
(_Error_formatter(const char*, unsigned int)): Adapt.
(_Error_formatter::_M_at): Rename in...
(_Error_formatter::_S_at): ...that and adapt.
* include/debug/macros.h (_GLIBCXX_DEBUG_VERIFY_AT_F): New.
(_GLIBCXX_DEBUG_VERIFY_AT, _GLIBCXX_DEBUG_VERIFY): Adapt.
* src/c++11/debug.cc (_Error_formatter::_M_error): Render _M_function
when available.

From-SVN: r260052

libstdc++-v3/ChangeLog
libstdc++-v3/include/debug/formatter.h
libstdc++-v3/include/debug/macros.h
libstdc++-v3/src/c++11/debug.cc

index 8c03e2f1d92bb8e63ed14b7b39186d6ed134b0e4..87bd39c9341c50f5d1d0d7264fef2dc483a2d193 100644 (file)
@@ -1,3 +1,14 @@
+2018-05-08  François Dumont  <fdumont@gcc.gnu.org>
+
+       * include/debug/formatter.h (_Error_formatter::_M_function): New.
+       (_Error_formatter(const char*, unsigned int)): Adapt.
+       (_Error_formatter::_M_at): Rename in...
+       (_Error_formatter::_S_at): ...that and adapt.
+       * include/debug/macros.h (_GLIBCXX_DEBUG_VERIFY_AT_F): New.
+       (_GLIBCXX_DEBUG_VERIFY_AT, _GLIBCXX_DEBUG_VERIFY): Adapt.
+       * src/c++11/debug.cc (_Error_formatter::_M_error): Render _M_function
+       when available.
+
 2018-05-08  Jonathan Wakely  <jwakely@redhat.com>
 
        * include/bits/regex_automaton.h (_NFA_base::_M_paren_stack, _NFA):
index 52a8762e75ad2ca62f80a16cc87e3e7870f2ef01..c160bd8432c7e5e6b5d4b0b88b04c512dc940043 100644 (file)
@@ -467,8 +467,10 @@ namespace __gnu_debug
 #endif
 
   private:
-    _Error_formatter(const char* __file, unsigned int __line)
+    _Error_formatter(const char* __file, unsigned int __line,
+                    const char* __function)
     : _M_file(__file), _M_line(__line), _M_num_parameters(0), _M_text(0)
+    , _M_function(__function)
     { }
 
 #if !_GLIBCXX_INLINE_VERSION
@@ -483,12 +485,13 @@ namespace __gnu_debug
     _Parameter         _M_parameters[__max_parameters];
     unsigned int       _M_num_parameters;
     const char*                _M_text;
+    const char*                _M_function;
 
   public:
     static _Error_formatter&
-    _M_at(const char* __file, unsigned int __line)
+    _S_at(const char* __file, unsigned int __line, const char* __function)
     {
-      static _Error_formatter __formatter(__file, __line);
+      static _Error_formatter __formatter(__file, __line, __function);
       return __formatter;
     }
   };
index 12eac2edbbf0df23e965d66f48bb8229a91aa037..6f901bc00314e6ed8c0de038f4c62e801b05f465 100644 (file)
  * the user error and where the error is reported.
  *
  */
-#define _GLIBCXX_DEBUG_VERIFY_AT(_Condition,_ErrorMessage,_File,_Line) \
+#define _GLIBCXX_DEBUG_VERIFY_AT_F(_Cond,_ErrMsg,_File,_Line,_Func)    \
   do                                                                   \
   {                                                                    \
-    if (! (_Condition))                                                        \
-      __gnu_debug::_Error_formatter::_M_at(_File, _Line)               \
-         ._ErrorMessage._M_error();                                    \
+    if (! (_Cond))                                                     \
+      __gnu_debug::_Error_formatter::_S_at(_File, _Line, _Func)                \
+       ._ErrMsg._M_error();                                            \
   } while (false)
 
-#define _GLIBCXX_DEBUG_VERIFY(_Condition,_ErrorMessage)                        \
-  _GLIBCXX_DEBUG_VERIFY_AT(_Condition,_ErrorMessage,__FILE__,__LINE__)
+#define _GLIBCXX_DEBUG_VERIFY_AT(_Cond,_ErrMsg,_File,_Line)            \
+  _GLIBCXX_DEBUG_VERIFY_AT_F(_Cond,_ErrMsg,_File,_Line,__PRETTY_FUNCTION__)
+
+#define _GLIBCXX_DEBUG_VERIFY(_Cond,_ErrMsg)                           \
+  _GLIBCXX_DEBUG_VERIFY_AT_F(_Cond, _ErrMsg, __FILE__, __LINE__,       \
+                            __PRETTY_FUNCTION__)
 
 // Verify that [_First, _Last) forms a valid iterator range.
 #define __glibcxx_check_valid_range(_First,_Last)                      \
index 7c0b540a7dfbe843dbf3e3c838fd1b60fd638f3b..89d387cdea5688fb2409bd011711fedf5bb49056 100644 (file)
@@ -923,9 +923,9 @@ namespace
            continue;
          }
 
-       if (*start != '%')
+       if (!num_parameters || *start != '%')
          {
-           // Normal char.
+           // Normal char or no parameter to look for.
            buf[bufindex++] = *start++;
            continue;
          }
@@ -1034,6 +1034,15 @@ namespace __gnu_debug
     if (ctx._M_max_length)
       ctx._M_wordwrap = true;
 
+    if (_M_function)
+      {
+       print_literal(ctx, "In function:\n");
+       print_string(ctx, _M_function, nullptr, 0);
+       print_literal(ctx, "\n");
+       ctx._M_first_line = true;
+       print_literal(ctx, "\n");
+      }
+
     print_literal(ctx, "Error: ");
 
     // Print the error message