Debug mode enhancements
François Dumont
frs.dumont@gmail.com
Wed Jun 24 19:59:00 GMT 2015
Hello
Is this one ok ?
François
On 12/06/2015 19:11, François Dumont wrote:
> Hi
>
> This is a patch to:
>
> - Enhance __get_distance to get a better feedback about distance between
> iterators so that we can take sharper decision about what is right or
> not. This function is now aware about safe iterators and leverage on
> those a little like std::distance does with C++ 11 list::iterator.
> - Make debug mode aware about iterator adapters reverse_iterator and
> move_iterator.
> - Thanks to previous points this patch also extend situations where it
> is possible to remove debug layers on iterators to lower performance
> hint of this mode. We now detect at runtime if we know enough about the
> iterator range to get rid of the potential debug layer.
>
> For the last point I introduced __gnu_debug::__unsafe which remove
> debug layer unconditionally in opposition to __gnu_debug::__base which
> do so only for random access iterator. The latter has been kept to be
> used in context of constructors.
>
> I had to introduced new debug headers to limit impact in
> stl_iterator.h. We shall not include debug.h here as the purpose is not
> to inject debug checks in the normal code.
>
> Note that the new __get_distance will be very useful to implement
> proper debug algos
>
> Here is the tricky part for me, the ChangeLog entry, much more
> complicated than the code :-)
>
> * include/bits/stl_iterator_base_types.h (_Iter_base): Limit definition
> to pre-C++11 mode.
> * include/debug/functions.h
> (__gnu_debug::__valid_range, __gnu_debug::__base): Move...
> * include/debug/safe_iterator.h
> (__gnu_debug::_Sequence_traits): New.
> (__gnu_debug::__get_distance_from_begin): New.
> (__gnu_debug::__get_distance_to_end): New.
> (__gnu_debug::_Safe_iterator<>::_M_valid_range): Expose iterator range
> distance information. Add optional check_dereferenceable parameter,
> default true.
> (__gnu_debug::_Distance_precision, __gnu_debug::__get_distance): Move
> default definition...
> (__gnu_debug::__get_distance): New overload for _Safe_iterator.
> (__gnu_debug::__unsafe): Likewise.
> * include/debug/helper_functions.h: ...here. New.
> (__gnu_debug::__unsafe): New helper function to remove safe iterator
> layer.
> * include/debug/stl_iterator.h: New. Include latter.
> * include/bits/stl_iterator.h: Include latter in debug mode.
> * include/debug/stl_iterator.tcc: Adapt.
> * include/debug/safe_local_iterator.h (__gnu_debug::__get_distance): Add
> overload for _Safe_local_iterator.
> (__gnu_debug::__unsafe): Likewise.
> * include/debug/safe_local_iterator.tcc: Adapt.
> * include/debug/macros.h (__glibcxx_check_valid_range2): New.
> (__glibcxx_check_insert_range): Add _Dist parameter.
> (__glibcxx_check_insert_range_after): Likewise.
> * include/debug/deque (deque<>::assign): Remove iterator debug layer
> when possible.
> (deque<>::insert): Likewise.
> * include/debug/forward_list (__glibcxx_check_valid_fl_range): New.
> (forward_list<>::splice_after): Use latter.
> (forward_list<>::assign): Remove iterator debug layer when possible.
> (forward_list<>::insert_after): Likewise.
> (__gnu_debug::_Sequence_traits<>): Partial specialization.
> * include/debug/list (list<>::assign): Remove iterator debug layer when
> possible.
> (list<>::insert): Likewise.
> [__gnu_debug::_Sequence_traits<>]: Partial specialization pre C++11 ABI.
> * include/debug/map.h (map<>::insert): Remove iterator debug layer when
> possible.
> * include/debug/multimap.h (multimap<>::insert): Likewise.
> * include/debug/set.h (set<>::insert): Likewise.
> * include/debug/multiset.h (multiset<>::insert): Likewise.
> * include/debug/string (basic_string<>::append, basic_string<>::assign,
> basic_string<>::insert, basic_string<>::replace): Likewise.
> * include/debug/unordered_map
> (unordered_map<>::insert, unordered_multimap<>::insert): Likewise.
> * include/debug/unordered_set
> (unordered_set<>::insert, unordered_multiset<>insert): Likewise.
> * include/debug/vector
> (vector<>::assign, vector<>::insert): Likewise.
> * include/Makefile.am: Add new debug headers.
> * include/Makefile.in: Regenerate.
>
> Being fully tested under Linux x86_64.
>
> François
>
More information about the Gcc-patches
mailing list