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

            Bug ID: 95377
           Summary: inconsistent behaviors at -O1
           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 48622
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48622&action=edit
a.out

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


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

Consider test-case:
...
$ cat small.c
char *pa;

void access (volatile char *ptr) {
  *ptr = 'x';
}

int main () {
  char a;
  pa = &a;
  access (pa);
  return 0;
}


...

When stepping through the program by using "stepi"
...
$ gcc -O1 -g small.c; gdb -q a.out
Reading symbols from a.out...
(gdb) b main
Breakpoint 1 at 0x401106: file small.c, line 9.
(gdb) r
Starting program: /home/yibiao/Debugger/a.out 

Breakpoint 1, main () at small.c:9
9         pa = &a;
(gdb) stepi
0x000000000040110b      9         pa = &a;
(gdb) 
access (ptr=0x7fffffffdf07 "") at small.c:4
4         *ptr = 'x';
(gdb) 
main () at small.c:11
11        return 0;
(gdb)
...

/**********************************************
As showed, when stepping with stepi, Line 10 is skipping over. While using
step, Line 10 is hit by gdb as follow:
***********************************************/

When stepping through the program by using step:
...
$ gcc -O1 -g small.c
$ gdb -q a.out
Reading symbols from a.out...
(gdb) b main
Breakpoint 1 at 0x401106: file small.c, line 9.
(gdb) r
Starting program: /home/yibiao/Debugger/a.out 

Breakpoint 1, main () at small.c:9
9         pa = &a;
(gdb) step
10        access (pa);
(gdb) 
access (ptr=0x7fffffffdf07 "") at small.c:4
4         *ptr = 'x';
(gdb) 
main () at small.c:11
11        return 0;
(gdb)


Considering that this might be caused by gdb, I also submit a bug report to gdb
as inspired by Tom de Vries :
https://sourceware.org/bugzilla/show_bug.cgi?id=26057

Reply via email to