From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 757E9398A7F6; Wed, 5 Jun 2024 15:59:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 757E9398A7F6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1717603145; bh=nY3/jzz3BVYrHIXnPKwm/+k/dxKLCA5EBjwnlCgJUsE=; h=From:To:Subject:Date:From; b=succ2wh7+QW9MRRn8p3H0Wk3MSELsR8vzP5gXr2P5udoe1Ny7IkW0W43Z8lvaZWlb XUvf3PF1O2CgzE+HqToT0zYY9hrLkqCWCTdzcWLoRC1J28N4+ajWqLv8hgIDlZ8X6y 5dNubCO3IsEVMFqzPRfE1eQK/5jgtJaAcwYdN7PM= From: "iamanonymous.cs at gmail dot com" To: gdb-prs@sourceware.org Subject: [Bug gdb/31849] New: Issue with Unexpected Behavior in GDB Stepping at Optimization Level O2 and O3 Date: Wed, 05 Jun 2024 15:59:04 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: gdb X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: iamanonymous.cs at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: 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 target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D31849 Bug ID: 31849 Summary: Issue with Unexpected Behavior in GDB Stepping at Optimization Level O2 and O3 Product: gdb Version: unknown Status: UNCONFIRMED Severity: normal Priority: P2 Component: gdb Assignee: unassigned at sourceware dot org Reporter: iamanonymous.cs at gmail dot com Target Milestone: --- The gdb and gcc versions are as follows:=20 $ gcc --version gcc (GCC) 15.0.0 20240509 (experimental) $ gdb --version GNU gdb (GDB) 15.0.50.20240512-git $ gcc -O2 -g small.c $ gdb a.out -q Reading symbols from a.out... (gdb) b main Breakpoint 1 at 0x401060: file small.c, line 43. (gdb) r Starting program: /root/a.out=20 Breakpoint 1, main () at small.c:43 43 asm volatile ("" : "+r" (x)); (gdb) s 44 foo (x); (gdb) s foo (x=3D1) at small.c:19 19 if (x =3D=3D 0) (gdb) s 25 else if (x =3D=3D 1) (gdb) s 17 foo (int x) (gdb) s foo (x=3D1) at small.c:28 28 int *b =3D __builtin_malloc (3 * sizeof (int)); (gdb)=20 ################################## When using GDB to debug the program compiled at optimization level O2 or O3, the expected behavior is that when the execution is stopped at line #25, stepping forward with the 'step' command should advance the execution to the next line. However, it has been observed that the program unexpectedly stop= s at line #17 instead. ################################## ################################## Here is the source code that can reproduce this problem.=20 $ cat small.c __attribute__((noinline, noclone)) void bar (int *b) { b[0] =3D b[1] =3D b[2] =3D 1; } __attribute__((noinline, noclone)) int baz (int x) { if (x !=3D 1) __builtin_abort (); } void=20 foo (int x) { if (x =3D=3D 0) { int *b =3D __builtin_malloc (3 * sizeof (int)); while (b[0]) ; } else if (x =3D=3D 1) { int i, j; int *b =3D __builtin_malloc (3 * sizeof (int)); for (i =3D 0; i < 2; i++) { bar (b); for (j =3D 0; j < 3; ++j) baz (b[j]); baz (b[0]); } } } int main () { int x =3D 1; asm volatile ("" : "+r" (x)); foo (x); return 0; } --=20 You are receiving this mail because: You are on the CC list for the bug.=