[Bug debug/105070] New: Missing debug info for switch statement

liyd2021 at gmail dot com gcc-bugzilla@gcc.gnu.org
Sun Mar 27 16:27:50 GMT 2022


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

            Bug ID: 105070
           Summary: Missing debug info for switch statement
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: liyd2021 at gmail dot com
  Target Milestone: ---

Affected versions: gcc 11.1.0, since gcc 9

(terminal) $ gcc-9 -v
Using built-in specs.
COLLECT_GCC=gcc-9
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
9.4.0-1ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-9
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-gnu-unique-object --disable-vtable-verify --enable-plugin
--enable-default-pie --with-system-zlib --with-target-system-zlib=auto
--enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib
--with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-9-yTrUTS/gcc-9-9.4.0/debian/tmp-nvptx/usr,hsa
--without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04)


Debugging the following program will directly hit "return 1" instead of the
"switch (x)" in this specific case.
Did not observe this problem on other switch-cases.

(terminal) $ cat a.c && gcc -g -OO a.c
extern void abort(void);

int foo(int x) {
  switch (x) {
  case 1:
  case 3:
  case 5:
    return 1;
  default:
    return 0;
  }
}

int main() {
  int i, r;
  for (i = 0; i < 6; i++) {
    r = foo(i);
    if(i == 1 || i == 3 || i == 5){
      if(r == 0){
        abort();
      }
    }
  }
  return 0;
}

--------------------

(terminal) $ gdb a.out
(gdb) b foo
Breakpoint 1 at 0x4011b3: file a.c, line 8.
(gdb) r
Breakpoint 1, foo (x=1) at a.c:8
8           return 1;
(gdb) c
Continuing.

Breakpoint 1, foo (x=3) at a.c:8
8           return 1;
(gdb) c
Continuing.

Breakpoint 1, foo (x=5) at a.c:8
8           return 1;

This bug seemed to be missing debug_line. 

(terminal) $ readelf --debug-dump=decodedline a.out
Contents of the .debug_line section:

CU: a.c:
File  Line    Starting address    View    Stmt
a.c      3            0x401185               x
a.c      8            0x4011b3               x  <-- line 4 is missing
a.c     10            0x4011ba               x
a.c     12            0x4011bf               x
a.c     14            0x4011c1               x


More information about the Gcc-bugs mailing list