From: François Dumont Date: Tue, 8 May 2018 19:41:02 +0000 (+0000) Subject: formatter.h (_Error_formatter::_M_function): New. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a5277405c8ec3cc34a48c1498abcfc3145046477;p=gcc.git formatter.h (_Error_formatter::_M_function): New. 2018-05-08 François Dumont * 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 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 8c03e2f1d92..87bd39c9341 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,14 @@ +2018-05-08 François Dumont + + * 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 * include/bits/regex_automaton.h (_NFA_base::_M_paren_stack, _NFA): diff --git a/libstdc++-v3/include/debug/formatter.h b/libstdc++-v3/include/debug/formatter.h index 52a8762e75a..c160bd8432c 100644 --- a/libstdc++-v3/include/debug/formatter.h +++ b/libstdc++-v3/include/debug/formatter.h @@ -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; } }; diff --git a/libstdc++-v3/include/debug/macros.h b/libstdc++-v3/include/debug/macros.h index 12eac2edbbf..6f901bc0031 100644 --- a/libstdc++-v3/include/debug/macros.h +++ b/libstdc++-v3/include/debug/macros.h @@ -38,16 +38,20 @@ * 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) \ diff --git a/libstdc++-v3/src/c++11/debug.cc b/libstdc++-v3/src/c++11/debug.cc index 7c0b540a7df..89d387cdea5 100644 --- a/libstdc++-v3/src/c++11/debug.cc +++ b/libstdc++-v3/src/c++11/debug.cc @@ -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