public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/31849] New: Issue with Unexpected Behavior in GDB Stepping at Optimization Level O2 and O3
@ 2024-06-05 15:59 iamanonymous.cs at gmail dot com
  2024-06-05 15:59 ` [Bug gdb/31849] " iamanonymous.cs at gmail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: iamanonymous.cs at gmail dot com @ 2024-06-05 15:59 UTC (permalink / raw)
  To: gdb-prs

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

            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: 

$ 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 

Breakpoint 1, main () at small.c:43
43        asm volatile ("" : "+r" (x));
(gdb) s
44        foo (x);
(gdb) s
foo (x=1) at small.c:19
19        if (x == 0)
(gdb) s
25        else if (x == 1)
(gdb) s
17      foo (int x)
(gdb) s
foo (x=1) at small.c:28
28            int *b = __builtin_malloc (3 * sizeof (int));
(gdb) 

##################################
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 stops at
line #17 instead.
##################################

##################################
Here is the source code that can reproduce this problem. 

$ cat small.c

__attribute__((noinline, noclone)) void
bar (int *b)
{
  b[0] = b[1] = b[2] = 1;
}

__attribute__((noinline, noclone)) int
baz (int x)
{
  if (x != 1)
    __builtin_abort ();
}

void 
foo (int x)
{
  if (x == 0)
    {
      int *b = __builtin_malloc (3 * sizeof (int));
      while (b[0])
        ;
    }
  else if (x == 1)
    {
      int i, j;
      int *b = __builtin_malloc (3 * sizeof (int));
      for (i = 0; i < 2; i++)
        {
          bar (b);
          for (j = 0; j < 3; ++j)
            baz (b[j]);
          baz (b[0]);
        }
    }
}

int
main ()
{
  int x = 1;
  asm volatile ("" : "+r" (x));
  foo (x);
  return 0;
}

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-06-08  4:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-05 15:59 [Bug gdb/31849] New: Issue with Unexpected Behavior in GDB Stepping at Optimization Level O2 and O3 iamanonymous.cs at gmail dot com
2024-06-05 15:59 ` [Bug gdb/31849] " iamanonymous.cs at gmail dot com
2024-06-05 16:02 ` iamanonymous.cs at gmail dot com
2024-06-05 16:16 ` iamanonymous.cs at gmail dot com
2024-06-06 14:29 ` tromey at sourceware dot org
2024-06-08  4:00 ` iamanonymous.cs at gmail dot com
2024-06-08  4:07 ` iamanonymous.cs at gmail dot com

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