https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95387

            Bug ID: 95387
           Summary: inconsistent behaviors at -Os
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yangyibiao at hust dot edu.cn
  Target Milestone: ---

Created attachment 48628
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48628&action=edit
a.out

$ gdb --version
GNU gdb (GDB) 10.0.50.20200517-git
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ gcc --version
gcc (GCC) 10.0.1 20200419 (experimental)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Consider test case:

$ cat small.c
#include <string.h>

int main () {
  char a1[4] = {1, 2, 3, 4};
  char a2[4] = {1, 2, 3, 4};
  int res = memcmp(a1, a2, 4);
  return res;
}


/******when using stepping using stepi, Line 5 is hit after line 6. ****/

$ gcc -Os -g small.c; gdb -q a.out
Reading symbols from a.out...
(gdb) b main
Breakpoint 1 at 0x401040: file small.c, line 4.
(gdb) r
Starting program: /home/yibiao/Debugger/a.out 

Breakpoint 1, main () at small.c:4
4         char a1[4] = {1, 2, 3, 4};
(gdb) si
0x0000000000401044      6         int res = memcmp(a1, a2, 4);
(gdb) si
0x0000000000401049      6         int res = memcmp(a1, a2, 4);
(gdb) si
0x000000000040104e      6         int res = memcmp(a1, a2, 4);
(gdb) si
0x0000000000401053      4         char a1[4] = {1, 2, 3, 4};
(gdb) si
5         char a2[4] = {1, 2, 3, 4};
(gdb) si
6         int res = memcmp(a1, a2, 4);
(gdb)


/****** when setting breakpoint, we can found that line 5 is hit before line 6
*******/

$ gcc -Os -g small.c; gdb -q a.out
Reading symbols from a.out...
(gdb) b 5
Breakpoint 1 at 0x40105b: file small.c, line 5.
(gdb) b 6
Breakpoint 2 at 0x401063: file small.c, line 6.
(gdb) r
Starting program: /home/yibiao/Debugger/a.out 

Breakpoint 1, main () at small.c:5
5         char a2[4] = {1, 2, 3, 4};
(gdb) c
Continuing.

Breakpoint 2, main () at small.c:6
6         int res = memcmp(a1, a2, 4);
(gdb)

Reply via email to