public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "i at maskray dot me" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug breakpoints/27394] New: Breakpoint set on vector code but not serial code within a lexical scope
Date: Thu, 11 Feb 2021 00:16:59 +0000	[thread overview]
Message-ID: <bug-27394-4717@http.sourceware.org/bugzilla/> (raw)

https://sourceware.org/bugzilla/show_bug.cgi?id=27394

            Bug ID: 27394
           Summary: Breakpoint set on vector code but not serial code
                    within a lexical scope
           Product: gdb
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: breakpoints
          Assignee: unassigned at sourceware dot org
          Reporter: i at maskray dot me
  Target Milestone: ---

int Foo(const int iterations, const int initial) {
  static int val = initial;

  for (int i = 0; i <= iterations; ++i)
    val += (i % 2 ? 50 : 25) * i;  // If you set a breakpoint on this line, it
will not get hit

  return val;
}

int main(int argc, char**) {
  return Foo(4 + argc, 5 + argc);
}


clang++ -g -fno-inline -O2 a.cc
# g++ -g -fno-inline -O3 a.cc  is similar. clang enables vectorization with -O2
gdb ./a.out -batch -ex 'b 5' -ex 'r'

The breakpoint is not triggered. (lldb has the same problem.)
The problem is that we have a vector code path (smaller address) and a serial
code path (larger address) under the same lexical scope.
The serial code path does not get a breakpoint.


gdb/linespec.c:2173 has such a comment

      /* For optimized code, the compiler can scatter one source line
         across disjoint ranges of PC values, even when no duplicate
         functions or inline functions are involved.  For example,
         'for (;;)' inside a non-template, non-inline, and non-ctor-or-dtor
         function can result in two PC ranges.  In this case, we don't
         want to set a breakpoint on the first PC of each range.  To filter
         such cases, we use containing blocks -- for each PC found
         above, we see if there are other PCs that are in the same
         block.  If yes, the other PCs are filtered out.  */

intermediate_results.size() is 4, matching the output of

  % llvm-dwarfdump -debug-line ./a.out | grep ' 5 .*is_stmt'
  # loop preheader for the vector code path
  0x00000000004011e9      5     13      1   0             0  is_stmt
  0x00000000004012ba      5     13      1   0             0  is_stmt
  # loop preheader for the serial code path
  0x0000000000401360      5     13      1   0             0  is_stmt
  0x0000000000401377      5      9      1   0             0  is_stmt

blocks[*] values are the same, presumably because after considering
DW_TAG_inlined_subroutine/DW_TAG_lexical_block (what else?),
the four addresses are in the same scope.
After deduplication, only the first address gets a breakpoint.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

             reply	other threads:[~2021-02-11  0:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-11  0:16 i at maskray dot me [this message]
2021-02-11  0:19 ` [Bug breakpoints/27394] Breakpoint set on vector code but not on " i at maskray dot me
2021-02-12  1:20 ` ctice42 at gmail dot com
2021-02-19  0:00 ` dblaikie at gmail dot com
2024-01-09 17:24 ` ssbssa at sourceware dot org

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=bug-27394-4717@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).