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

            Bug ID: 92204
           Summary: Confusing GDB output for an optimized C program
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shuo.d at outlook dot com
  Target Milestone: ---

I compiled the following code using the current gcc trunk with -O3, and then
set a breakpoint before the return statement using the current gdb trunk. When
the program stopped at that breakpoint, I printed the value of the variable i
and I got 0. I think it should be 1 in this case.

I'm not sure whether it is a problem of gcc or gdb.






$ cat src.c 
int main(void)
{
        int i = 0;
        i++;
        return 0;
}
$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/home/absozero/trunk/root-gcc/libexec/gcc/x86_64-pc-linux-gnu/10.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/home/absozero/trunk/root-gcc
--enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.0.0 20191023 (experimental) [trunk revision 277309] (GCC) 
$ gdb-trunk -v
GNU gdb (GDB) 9.0.50.20191023-git
Copyright (C) 2019 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-trunk -O3 -g src.c 
$ gdb-trunk a.out 
GNU gdb (GDB) 9.0.50.20191023-git
Copyright (C) 2019 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.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.out...
(gdb) l
1       int main(void)
2       {
3               int i = 0;
4               i++;
5               return 0;
6       }
(gdb) b 5
Breakpoint 1 at 0x4003a0: file src.c, line 5.
(gdb) r
Starting program: /home/sding/oct23/reduced/a.out 

Breakpoint 1, main () at src.c:5
5               return 0;
(gdb) p i
$1 = 0
(gdb) q
A debugging session is active.

        Inferior 1 [process 27339] will be killed.

Quit anyway? (y or n) y
$ 






I also checked the DWARF .debug_line information. The starting address 0x4003a0
corresponds to many line numbers.

I don't know what the View column means.






$ readelf -wL a.out 
Contents of the .debug_line section:

CU: src.c:
File name                            Line number    Starting address    View
src.c                                          2            0x4003a0
src.c                                          3            0x4003a0       1
src.c                                          4            0x4003a0       2
src.c                                          5            0x4003a0       3
src.c                                          6            0x4003a0       4
src.c                                          6            0x4003a3


$

Reply via email to