Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFA] unexpected multiple location for breakpoint
Date: Wed, 29 Dec 2010 06:08:00 -0000	[thread overview]
Message-ID: <20101229054841.GF2396@adacore.com> (raw)
In-Reply-To: <83tyhxbthv.fsf@gnu.org>

> > If this is a bug, then the only solution I can think of is inserting
> > a breakpoint at *every* instances of line 53, regardless of
> > lexical-block relationships.
> 
> When would that be worse than what we have now?

I worry about the effect at -O0. It is common to see the same source
line being split across the code.  For instance, with conditional
loops, the condition evaluation is often placed at the end of the
loop, and its code is associated to the initial line.

See Eg. gdb.base/call-ar-st.c, where we have:

    1146 int main ()  {
           [bunch of declarations snipped]
    1193   /* Initialize arrays
    1194    */
    1195   for (index = 0; index < 120; index++) {
    1196       if ((index%2) == 0) char_array[index] = 'Z';
    1197          else char_array[index] = 'a';
    1198   }

If we try to insert a breakpoint on line 1195, we get:

   (gdb) break call-ar-st.c:1195
   Breakpoint 1: file /[...]/call-ar-st.c, line 1195. (2 locations)^M

Inspecting the line table, we find that it looks like this: 1195, 1196,
1197, and then back to 1195. So the double-location breakpoint is
expected if we decide to break everywhere.

There is a slight side-issue with my patch where breaking on "main"
also causes 2 breakpoints to be inserted, but I consider that a buglet
because we have special logic to avoid the expansion when breaking on
a function (or so I thought!).

  (gdb) b main
  Breakpoint 1 at 0x401906: file /[...]/call-ar-st.c, line 1195. (2 locations)
  (gdb) info break
  Num     Type           Disp Enb Address            What
  1       breakpoint     keep y   <MULTIPLE>         
  1.1                         y     0x0000000000401906 in main
                                                 at call-ar-st.c:1195
  1.2                         y     0x000000000040193f in main
                                                 at call-ar-st.c:1195

Note that we also have the following explicit comment in the code:

  /* For optimized code, compiler can scatter one source line accross
     disjoint ranges of PC values, even when no duplicate functions
     or inline functions are involved.  For example, 'for (;;)' inside
     non-template non-inline non-ctor-or-dtor function can result
     in two PC ranges.  In this case, we don't want to set breakpoint
     on first PC of each range.  [...] */

For the record, attached is the patch that I used.  It was written on
top of the initially proposed patch (in this thread), but just purely
for convenience. The piece that checks the next entry is to avoid
inserting a breakpoint on 2 blocks if the two blocks are consecutive.
This is often the case with functions where the compiler emits a line
entry with the same line number to mark the end of the function prologue...

-- 
Joel


  reply	other threads:[~2010-12-29  5:48 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-23  1:10 Joel Brobecker
2010-11-26 17:29 ` Joel Brobecker
2010-11-27 18:35   ` Daniel Jacobowitz
2010-12-10 12:23     ` Joel Brobecker
2010-12-28 11:50       ` Joel Brobecker
2010-12-28 20:15         ` Eli Zaretskii
2010-12-29  6:08           ` Joel Brobecker [this message]
2010-12-29  8:08             ` Joel Brobecker
2010-12-29 19:30             ` Eli Zaretskii
2010-12-30 20:40               ` Joel Brobecker
2010-12-30 21:03                 ` Eli Zaretskii
2010-12-31  6:35                 ` Michael Snyder

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=20101229054841.GF2396@adacore.com \
    --to=brobecker@adacore.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.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