public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: "François Dumont" <frs.dumont@gmail.com>
To: "libstdc++@gcc.gnu.org" <libstdc++@gcc.gnu.org>
Subject: Re: Alternative to __FILE__/__LINE__
Date: Sun, 18 Mar 2018 17:04:00 -0000	[thread overview]
Message-ID: <d5a9676d-fd47-aa72-eb2c-5997289c43ae@gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.21.1803042151140.21925@stedding.saclay.inria.fr>

On 04/03/2018 21:55, Marc Glisse wrote:
> On Sun, 4 Mar 2018, François Dumont wrote:
>
>>     Debug mode is using __FILE__/__LINE__ to show where the assertion 
>> took place. So assertion looks like this:
>>
>> /home/fdt/dev/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/debug/deque:175: 
>>
>> Error: function requires a valid iterator range [__first, __last).
>>
>>     But IMHO a smarter information would be to provide the file:line 
>> in the source code that generated this assertion so that users could 
>> more easily go to the faulty code.
>
> How about printing a backtrace then? Though at some point the user 
> might want to start a debugger to get more information.
>
I eventually made use of __PRETTY_FUNCTION__ and glibc backtrace 
function which is already used by the profile mode.

With all those additional info debug assertions are much clearer and 
easier to detect in code. For instance:

/home/fdt/dev/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/debug/deque:175:
In function:
     void std::__debug::deque<_Tp, _Allocator>::assign(_InputIterator,
     _InputIterator) [with _InputIterator = const int*;
     <template-parameter-2-2> = void; _Tp = int; _Allocator =
     std::allocator<int>]

Backtrace:
     ./assign1_neg.exe() [0x4046b8]
     ./assign1_neg.exe() [0x400f19]
     /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) 
[0x7fc7a12f3830]
     ./assign1_neg.exe() [0x400f79]

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

Objects involved in the operation:
     iterator "__first" @ 0x0x7ffd79799140 {
       type = int const* (constant iterator);
     }
     iterator "__last" @ 0x0x7ffd79799148 {
       type = int const* (constant iterator);
     }

And with the help of the addr2line tool you can easily find where faulty 
code it.

I'll commit that once back in stage 1.

François

      parent reply	other threads:[~2018-03-18 17:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-04 20:18 François Dumont
2018-03-04 20:55 ` Marc Glisse
2018-03-04 21:30   ` Petr Ovtchenkov
2018-03-05  6:19     ` François Dumont
2018-03-18 17:04   ` François Dumont [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d5a9676d-fd47-aa72-eb2c-5997289c43ae@gmail.com \
    --to=frs.dumont@gmail.com \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).