public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "dblaikie at gmail dot com" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug c++/17315] New: 'until' behavion in watchpoint.c (for loops) incompatible with loop condition instructions at the top of the loop
Date: Tue, 26 Aug 2014 22:20:00 -0000	[thread overview]
Message-ID: <bug-17315-4717@http.sourceware.org/bugzilla/> (raw)

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

            Bug ID: 17315
           Summary: 'until' behavion in watchpoint.c (for loops)
                    incompatible with loop condition instructions at the
                    top of the loop
           Product: gdb
           Version: 7.7
            Status: NEW
          Severity: normal
          Priority: P2
         Component: c++
          Assignee: unassigned at sourceware dot org
          Reporter: dblaikie at gmail dot com

Simplifying the watchpoint.c code down to:

  void func() {}

  int main() {
    int a;
    for (a = 0; a != 2; ++a) {
      func();
    }
    return 0;
  }

And running this through clang (assembly attached) and gdb, the following
behavior is observed:

=> 0x00000000004005af <main+15>:        c7 45 f8 00 00 00 00    movl  
$0x0,-0x8(%rbp)
(gdb) until
=> 0x00000000004005c3 <main+35>:        e8 c8 ff ff ff  callq  0x400590 <func>
(gdb) 
=> 0x00000000004005c8 <main+40>:        8b 45 f8        mov    -0x8(%rbp),%eax
   0x00000000004005cb <main+43>:        05 01 00 00 00  add    $0x1,%eax
   0x00000000004005d0 <main+48>:        89 45 f8        mov    %eax,-0x8(%rbp)
(gdb) 
=> 0x00000000004005c3 <main+35>:        e8 c8 ff ff ff  callq  0x400590 <func>

so 'until' doesn't cause the loop to be skipped at all - continuing to run
'until' will just behave as though the user is stepping through the entire
loop.

I believe the issue here is that Clang keeps the loop condition at the top of
the loop, whereas GCC puts it at the end, the theory being 'until' really looks
for an instruction with a higher PC than the /last/ instruction on the line you
started at, not the specific instruction you started at.

(eg: while I ran "until" from <main+40>, I went through 40, 43, 48, then
<main+51> jumped up to the top of the loop (+22) but on the same line according
to the line table, continued on to 29, and then to 35 - since 35 is on a
distinct line from 29 and 29 > 35, GDB stopped here, even though 40 !> 35)

And GCC puts the condition at the end of the loop, so you go from increment, to
condition, then jump up from the condition to the body - changing lines and
decreasing the PC, so that causes until to skip that and keep going... until
eventually it gets out of the loop.

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


             reply	other threads:[~2014-08-26 22:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-26 22:20 dblaikie at gmail dot com [this message]
2021-12-09 14:34 ` [Bug c++/17315] " blarsen at redhat dot com
2022-01-05 20:31 ` blarsen at redhat dot com
2022-02-11 15:15 ` cvs-commit at gcc dot gnu.org
2022-05-17 19:26 ` blarsen at redhat dot com

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-17315-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).