From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17485 invoked by alias); 26 Aug 2014 22:20:29 -0000 Mailing-List: contact gdb-prs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-prs-owner@sourceware.org Received: (qmail 17462 invoked by uid 48); 26 Aug 2014 22:20:29 -0000 From: "dblaikie at gmail dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: c++ X-Bugzilla-Version: 7.7 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dblaikie at gmail dot com X-Bugzilla-Status: NEW X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-q3/txt/msg00354.txt.bz2 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 : c7 45 f8 00 00 00 00 movl $0x0,-0x8(%rbp) (gdb) until => 0x00000000004005c3 : e8 c8 ff ff ff callq 0x400590 (gdb) => 0x00000000004005c8 : 8b 45 f8 mov -0x8(%rbp),%eax 0x00000000004005cb : 05 01 00 00 00 add $0x1,%eax 0x00000000004005d0 : 89 45 f8 mov %eax,-0x8(%rbp) (gdb) => 0x00000000004005c3 : e8 c8 ff ff ff callq 0x400590 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 , I went through 40, 43, 48, then 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.