Bug 26064 - inconsistent behaviors at -O2
Summary: inconsistent behaviors at -O2
Status: RESOLVED DUPLICATE of bug 25507
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-30 02:58 UTC by Anonymous
Modified: 2021-01-13 13:02 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anonymous 2020-05-30 02:58:08 UTC
Consider test case:
...
$ cat small.c
#include <string.h>

volatile int one = 1;

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

When stepping using step Line 7 is not hit by gdb.
...
$ gcc -O2 -g small.c; gdb -q a.out
Reading symbols from a.out...
(gdb) b main
Breakpoint 1 at 0x401040: file small.c, line 6.
(gdb) r
Starting program: /home/yibiao/Debugger/a.out 

Breakpoint 1, main () at small.c:6
6	  char a1[] = {(char)one, 2, 3, 4};
(gdb) step
8	  int res = memcmp (a1, a2, 5 + one);
(gdb) 
...

When stepping using stepi, Line 7 is hit after Line 6 by gdb.
...
$ gcc -O2 -g small.c; gdb -q a.out
Reading symbols from a.out...
(gdb) b main
Breakpoint 1 at 0x401040: file small.c, line 6.
(gdb) si
The program is not being run.
(gdb) r
Starting program: /home/yibiao/Debugger/a.out 

Breakpoint 1, main () at small.c:6
6	  char a1[] = {(char)one, 2, 3, 4};
(gdb) si
0x0000000000401044	6	  char a1[] = {(char)one, 2, 3, 4};
(gdb) si
0x000000000040104a	7	  char a2[] = {1, (char)(2*one), 3, 4};
(gdb) 



$ 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.
Comment 1 Anonymous 2021-01-13 13:02:57 UTC
gdb does not support location views. this is all known behaviour. 

(gdb) maint info line-table
objfile: /home/yibiao/DeVIL/a.out ((struct objfile *) 0x557a30fda120)
compunit_symtab: ((struct compunit_symtab *) 0x557a30fd1400)
symtab: /home/yibiao/DeVIL/small.c ((struct symtab *) 0x557a30fd1480)
linetable: ((struct linetable *) 0x557a3101af00):
INDEX  LINE   ADDRESS            IS-STMT 
0      5      0x0000555555555080 Y 
1      7      0x0000555555555088   
2      6      0x000055555555508d   
3      7      0x00005555555550a1   
4      8      0x00005555555550a6   
5      6      0x00005555555550ae   
6      7      0x00005555555550b3 Y 
7      8      0x00005555555550b3 Y 
8      7      0x00005555555550b3   
9      6      0x00005555555550b8   
10     6      0x00005555555550bb   
11     7      0x00005555555550c5   
12     8      0x00005555555550cb   
13     7      0x00005555555550d1   
14     8      0x00005555555550d3   
15     7      0x00005555555550d6   
16     8      0x00005555555550da   
17     9      0x00005555555550e2 Y 
18     10     0x00005555555550e2   
19     END    0x00005555555550fc Y

*** This bug has been marked as a duplicate of bug 25507 ***