Re: Demangle symbols in debug assertion messages

2015-05-21 Thread Jonathan Wakely

On 20/05/15 21:45 +0200, François Dumont wrote:

On 20/05/2015 12:19, Jonathan Wakely wrote:
Does this fix https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65392 ?


With the patch this code of the bug report generates the following 
debug message:


/home/fdt/dev/gcc/build/x86_64-unknown-linux-gnu/libstdc++-v3/include/debug/safe_iterator.h:395:
   error: attempt to retreat a past-the-end iterator 2 steps, which falls
   outside its valid range.

Objects involved in the operation:
iterator @ 0x0x7fff32365c50 {
 type = 
__gnu_debug::_Safe_iteratorstd::__cxx1998::_Deque_iteratorint, int, 
int*, std::__debug::dequeint, std::allocatorint   (mutable 
iterator);

 state = past-the-end;
 references sequence with type `std::__debug::dequeint, 
std::allocatorint ' @ 0x0x7fff32365cd0

}

which looks nice.

However I wouldn't say that bug is fixed because debug mode do not 
generate mangle name, it simply rely on typeid to get it. Shouldn't 
bug report be saying so ? Whatever, symbol generated by typeid can be 
demangle by __cxa_demangle so it mustn't be that bad.


I was trying to demangle the names with c++filt, which failed. Users
should not have to write a C++ program using __cxa_demangle to read
the output.

If they are automatically demangled now then the bug is fixed.



Re: Demangle symbols in debug assertion messages

2015-05-20 Thread Jonathan Wakely

On 20/05/15 11:17 +0100, Jonathan Wakely wrote:

On 04/05/15 22:31 +0200, François Dumont wrote:

Hi

  Here is  the patch to demangle symbols in debug messages. I have 
also simplify code in formatter.h.


  Here is an example of assertion message:

/home/fdt/dev/gcc/build/x86_64-unknown-linux-gnu/libstdc++-v3/include/debug/functions.h:213:
  error: function requires a valid iterator range [__first, __last).

Objects involved in the operation:
iterator __first @ 0x0x7fff165d68b0 {
type = 
__gnu_debug::_Safe_iterator__gnu_cxx::__normal_iteratorint*, 
std::__cxx1998::vectorint, std::allocatorint  , 
std::__debug::vectorint, std::allocatorint   (mutable 
iterator);

state = dereferenceable;
references sequence with type `std::__debug::vectorint, 
std::allocatorint ' @ 0x0x7fff165d69d0

}
iterator __last @ 0x0x7fff165d68e0 {
type = 
__gnu_debug::_Safe_iterator__gnu_cxx::__normal_iteratorint*, 
std::__cxx1998::vectorint, std::allocatorint  , 
std::__debug::vectorint, std::allocatorint   (mutable 
iterator);

state = dereferenceable;
references sequence with type `std::__debug::vectorint, 
std::allocatorint ' @ 0x0x7fff165d69d0

}


  * include/debug/formatter.h (_GLIBCXX_TYPEID): New macro to simplify
  usage of typeid.
  (_Error_formatter::_M_print_type): New.
  * src/c++11/debug.cc
  (_Error_formatter::_Parameter::_M_print_field): Use latter.
  (_Error_formatter::_M_print_type): Implement latter using
  __cxaabiv1::__cxa_demangle to print demangled type name.

I just hope that __cxa_demangle is portable.


It's provided by GCC itself so is always available in the runtime.
(It is also portable, because it's defined by the Itanium C++ ABI).



Ok to commit ?


Yes, this is great, thanks!


Does this fix https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65392 ?


Re: Demangle symbols in debug assertion messages

2015-05-20 Thread Jonathan Wakely

On 04/05/15 22:31 +0200, François Dumont wrote:

Hi

   Here is  the patch to demangle symbols in debug messages. I have 
also simplify code in formatter.h.


   Here is an example of assertion message:

/home/fdt/dev/gcc/build/x86_64-unknown-linux-gnu/libstdc++-v3/include/debug/functions.h:213:
   error: function requires a valid iterator range [__first, __last).

Objects involved in the operation:
iterator __first @ 0x0x7fff165d68b0 {
 type = 
__gnu_debug::_Safe_iterator__gnu_cxx::__normal_iteratorint*, 
std::__cxx1998::vectorint, std::allocatorint  , 
std::__debug::vectorint, std::allocatorint   (mutable iterator);

 state = dereferenceable;
 references sequence with type `std::__debug::vectorint, 
std::allocatorint ' @ 0x0x7fff165d69d0

}
iterator __last @ 0x0x7fff165d68e0 {
 type = 
__gnu_debug::_Safe_iterator__gnu_cxx::__normal_iteratorint*, 
std::__cxx1998::vectorint, std::allocatorint  , 
std::__debug::vectorint, std::allocatorint   (mutable iterator);

 state = dereferenceable;
 references sequence with type `std::__debug::vectorint, 
std::allocatorint ' @ 0x0x7fff165d69d0

}


   * include/debug/formatter.h (_GLIBCXX_TYPEID): New macro to simplify
   usage of typeid.
   (_Error_formatter::_M_print_type): New.
   * src/c++11/debug.cc
   (_Error_formatter::_Parameter::_M_print_field): Use latter.
   (_Error_formatter::_M_print_type): Implement latter using
   __cxaabiv1::__cxa_demangle to print demangled type name.

I just hope that __cxa_demangle is portable.


It's provided by GCC itself so is always available in the runtime.
(It is also portable, because it's defined by the Itanium C++ ABI).



Ok to commit ?


Yes, this is great, thanks!



Re: Demangle symbols in debug assertion messages

2015-05-20 Thread François Dumont

On 20/05/2015 12:19, Jonathan Wakely wrote:

On 20/05/15 11:17 +0100, Jonathan Wakely wrote:

On 04/05/15 22:31 +0200, François Dumont wrote:

Hi

  Here is  the patch to demangle symbols in debug messages. I have 
also simplify code in formatter.h.


  Here is an example of assertion message:

/home/fdt/dev/gcc/build/x86_64-unknown-linux-gnu/libstdc++-v3/include/debug/functions.h:213: 


  error: function requires a valid iterator range [__first, __last).

Objects involved in the operation:
iterator __first @ 0x0x7fff165d68b0 {
type = 
__gnu_debug::_Safe_iterator__gnu_cxx::__normal_iteratorint*, 
std::__cxx1998::vectorint, std::allocatorint  , 
std::__debug::vectorint, std::allocatorint   (mutable iterator);

state = dereferenceable;
references sequence with type `std::__debug::vectorint, 
std::allocatorint ' @ 0x0x7fff165d69d0

}
iterator __last @ 0x0x7fff165d68e0 {
type = 
__gnu_debug::_Safe_iterator__gnu_cxx::__normal_iteratorint*, 
std::__cxx1998::vectorint, std::allocatorint  , 
std::__debug::vectorint, std::allocatorint   (mutable iterator);

state = dereferenceable;
references sequence with type `std::__debug::vectorint, 
std::allocatorint ' @ 0x0x7fff165d69d0

}


  * include/debug/formatter.h (_GLIBCXX_TYPEID): New macro to simplify
  usage of typeid.
  (_Error_formatter::_M_print_type): New.
  * src/c++11/debug.cc
  (_Error_formatter::_Parameter::_M_print_field): Use latter.
  (_Error_formatter::_M_print_type): Implement latter using
  __cxaabiv1::__cxa_demangle to print demangled type name.

I just hope that __cxa_demangle is portable.


It's provided by GCC itself so is always available in the runtime.
(It is also portable, because it's defined by the Itanium C++ ABI).



Ok to commit ?


Yes, this is great, thanks!


Does this fix https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65392 ?

With the patch this code of the bug report generates the following debug 
message:


/home/fdt/dev/gcc/build/x86_64-unknown-linux-gnu/libstdc++-v3/include/debug/safe_iterator.h:395:
error: attempt to retreat a past-the-end iterator 2 steps, which falls
outside its valid range.

Objects involved in the operation:
iterator @ 0x0x7fff32365c50 {
  type = 
__gnu_debug::_Safe_iteratorstd::__cxx1998::_Deque_iteratorint, int, 
int*, std::__debug::dequeint, std::allocatorint   (mutable iterator);

  state = past-the-end;
  references sequence with type `std::__debug::dequeint, 
std::allocatorint ' @ 0x0x7fff32365cd0

}

which looks nice.

However I wouldn't say that bug is fixed because debug mode do not 
generate mangle name, it simply rely on typeid to get it. Shouldn't bug 
report be saying so ? Whatever, symbol generated by typeid can be 
demangle by __cxa_demangle so it mustn't be that bad.


François



Re: Demangle symbols in debug assertion messages

2015-05-19 Thread François Dumont

Hello

Is it ok ?

François

On 04/05/2015 22:31, François Dumont wrote:

Hi

Here is  the patch to demangle symbols in debug messages. I have 
also simplify code in formatter.h.


Here is an example of assertion message:

/home/fdt/dev/gcc/build/x86_64-unknown-linux-gnu/libstdc++-v3/include/debug/functions.h:213: 


error: function requires a valid iterator range [__first, __last).

Objects involved in the operation:
iterator __first @ 0x0x7fff165d68b0 {
  type = 
__gnu_debug::_Safe_iterator__gnu_cxx::__normal_iteratorint*, 
std::__cxx1998::vectorint, std::allocatorint  , 
std::__debug::vectorint, std::allocatorint   (mutable iterator);

  state = dereferenceable;
  references sequence with type `std::__debug::vectorint, 
std::allocatorint ' @ 0x0x7fff165d69d0

}
iterator __last @ 0x0x7fff165d68e0 {
  type = 
__gnu_debug::_Safe_iterator__gnu_cxx::__normal_iteratorint*, 
std::__cxx1998::vectorint, std::allocatorint  , 
std::__debug::vectorint, std::allocatorint   (mutable iterator);

  state = dereferenceable;
  references sequence with type `std::__debug::vectorint, 
std::allocatorint ' @ 0x0x7fff165d69d0

}


* include/debug/formatter.h (_GLIBCXX_TYPEID): New macro to simplify
usage of typeid.
(_Error_formatter::_M_print_type): New.
* src/c++11/debug.cc
(_Error_formatter::_Parameter::_M_print_field): Use latter.
(_Error_formatter::_M_print_type): Implement latter using
__cxaabiv1::__cxa_demangle to print demangled type name.

I just hope that __cxa_demangle is portable.

Ok to commit ?

François





Demangle symbols in debug assertion messages

2015-05-04 Thread François Dumont

Hi

Here is  the patch to demangle symbols in debug messages. I have 
also simplify code in formatter.h.


Here is an example of assertion message:

/home/fdt/dev/gcc/build/x86_64-unknown-linux-gnu/libstdc++-v3/include/debug/functions.h:213:
error: function requires a valid iterator range [__first, __last).

Objects involved in the operation:
iterator __first @ 0x0x7fff165d68b0 {
  type = __gnu_debug::_Safe_iterator__gnu_cxx::__normal_iteratorint*, 
std::__cxx1998::vectorint, std::allocatorint  , 
std::__debug::vectorint, std::allocatorint   (mutable iterator);

  state = dereferenceable;
  references sequence with type `std::__debug::vectorint, 
std::allocatorint ' @ 0x0x7fff165d69d0

}
iterator __last @ 0x0x7fff165d68e0 {
  type = __gnu_debug::_Safe_iterator__gnu_cxx::__normal_iteratorint*, 
std::__cxx1998::vectorint, std::allocatorint  , 
std::__debug::vectorint, std::allocatorint   (mutable iterator);

  state = dereferenceable;
  references sequence with type `std::__debug::vectorint, 
std::allocatorint ' @ 0x0x7fff165d69d0

}


* include/debug/formatter.h (_GLIBCXX_TYPEID): New macro to simplify
usage of typeid.
(_Error_formatter::_M_print_type): New.
* src/c++11/debug.cc
(_Error_formatter::_Parameter::_M_print_field): Use latter.
(_Error_formatter::_M_print_type): Implement latter using
__cxaabiv1::__cxa_demangle to print demangled type name.

I just hope that __cxa_demangle is portable.

Ok to commit ?

François

diff --git a/libstdc++-v3/include/debug/formatter.h b/libstdc++-v3/include/debug/formatter.h
index 6767cd9..32dcf92 100644
--- a/libstdc++-v3/include/debug/formatter.h
+++ b/libstdc++-v3/include/debug/formatter.h
@@ -31,7 +31,17 @@
 
 #include bits/c++config.h
 #include bits/cpp_type_traits.h
-#include typeinfo
+
+#if __cpp_rtti
+# include typeinfo
+# define _GLIBCXX_TYPEID(_Type) typeid(_Type)
+#else
+namespace std
+{
+  class type_info;
+}
+# define _GLIBCXX_TYPEID(_Type) 0
+#endif
 
 namespace __gnu_debug
 {
@@ -218,21 +228,13 @@ namespace __gnu_debug
 	{
 	  _M_variant._M_iterator._M_name = __name;
 	  _M_variant._M_iterator._M_address = __it;
-#if __cpp_rtti
-	  _M_variant._M_iterator._M_type = typeid(__it);
-#else
-	  _M_variant._M_iterator._M_type = 0;
-#endif
+	  _M_variant._M_iterator._M_type = _GLIBCXX_TYPEID(__it);
 	  _M_variant._M_iterator._M_constness =
 	std::__are_same_Safe_iterator_Iterator, _Sequence,
 			typename _Sequence::iterator::
 	  __value ? __mutable_iterator : __const_iterator;
 	  _M_variant._M_iterator._M_sequence = __it._M_get_sequence();
-#if __cpp_rtti
-	  _M_variant._M_iterator._M_seq_type = typeid(_Sequence);
-#else
-	  _M_variant._M_iterator._M_seq_type = 0;
-#endif
+	  _M_variant._M_iterator._M_seq_type = _GLIBCXX_TYPEID(_Sequence);
 
 	  if (__it._M_singular())
 	_M_variant._M_iterator._M_state = __singular;
@@ -256,21 +258,13 @@ namespace __gnu_debug
 	{
 	  _M_variant._M_iterator._M_name = __name;
 	  _M_variant._M_iterator._M_address = __it;
-#if __cpp_rtti
-	  _M_variant._M_iterator._M_type = typeid(__it);
-#else
-	  _M_variant._M_iterator._M_type = 0;
-#endif
+	  _M_variant._M_iterator._M_type = _GLIBCXX_TYPEID(__it);
 	  _M_variant._M_iterator._M_constness =
 	std::__are_same_Safe_local_iterator_Iterator, _Sequence,
 			typename _Sequence::local_iterator::
 	  __value ? __mutable_iterator : __const_iterator;
 	  _M_variant._M_iterator._M_sequence = __it._M_get_sequence();
-#if __cpp_rtti
-	  _M_variant._M_iterator._M_seq_type = typeid(_Sequence);
-#else
-	  _M_variant._M_iterator._M_seq_type = 0;
-#endif
+	  _M_variant._M_iterator._M_seq_type = _GLIBCXX_TYPEID(_Sequence);
 
 	  if (__it._M_singular())
 	_M_variant._M_iterator._M_state = __singular;
@@ -291,11 +285,7 @@ namespace __gnu_debug
 	{
 	  _M_variant._M_iterator._M_name = __name;
 	  _M_variant._M_iterator._M_address = __it;
-#if __cpp_rtti
-	  _M_variant._M_iterator._M_type = typeid(__it);
-#else
-	  _M_variant._M_iterator._M_type = 0;
-#endif
+	  _M_variant._M_iterator._M_type = _GLIBCXX_TYPEID(__it);
 	  _M_variant._M_iterator._M_constness = __mutable_iterator;
 	  _M_variant._M_iterator._M_state = __it? __unknown_state : __singular;
 	  _M_variant._M_iterator._M_sequence = 0;
@@ -308,11 +298,7 @@ namespace __gnu_debug
 	{
 	  _M_variant._M_iterator._M_name = __name;
 	  _M_variant._M_iterator._M_address = __it;
-#if __cpp_rtti
-	  _M_variant._M_iterator._M_type = typeid(__it);
-#else
-	  _M_variant._M_iterator._M_type = 0;
-#endif
+	  _M_variant._M_iterator._M_type = _GLIBCXX_TYPEID(__it);
 	  _M_variant._M_iterator._M_constness = __const_iterator;
 	  _M_variant._M_iterator._M_state = __it? __unknown_state : __singular;
 	  _M_variant._M_iterator._M_sequence = 0;
@@ -325,11 +311,7 @@ namespace __gnu_debug
 	{
 	  _M_variant._M_iterator._M_name = __name;
 	  _M_variant._M_iterator._M_address = __it;
-#if __cpp_rtti
-	  _M_variant._M_iterator._M_type = typeid(__it);
-#else
-	  _M_variant._M_iterator._M_type = 0;