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

            Bug ID: 99457
           Summary: gcc/gdb -gstabs+ is buggy.
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jay.krell at cornell dot edu
  Target Milestone: ---

gcc/gdb -gstabs+ is buggy.
Could be either, I didn't investigate.
The codegen is correct.
That's ok, I didn't really need it, I'll use regular -g.

$ cat 1.c
#include <stdio.h>
int main()
{
        char a[100] = {0};
        printf("%d\n", a[0]);
}

$ gcc --version
gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0

$ gcc -gstabs+ 1.c

 # correct output
$ ./a.out
0

$ gdb --version
GNU gdb (Ubuntu 9.1-0ubuntu1) 9.1

$ gdb ./a.out
(gdb) break main
(gdb) r

Breakpoint 1, main () at 1.c:3
3       {
(gdb) n
4               char a[100] = {0};
(gdb)
5               printf("%d\n", a[0]);
(gdb) p a
$1 =
"@\003\000\000@\003\000\000@\003\000\000@\003\000\000@\003\000\000@\003\000\000@\003\000\000@\003\000\000@\003\000\000@\003",
'\000' <repeats 11 times>, "\001", '\000' <repeats 49 times>
(gdb) p a[0]
$2 = 64 '@'
(gdb) disas
Dump of assembler code for function main:
   0x0000555555555169 <+0>:     endbr64
   0x000055555555516d <+4>:     push   %rbp
   0x000055555555516e <+5>:     mov    %rsp,%rbp
   0x0000555555555171 <+8>:     sub    $0x70,%rsp
   0x0000555555555175 <+12>:    mov    %fs:0x28,%rax
   0x000055555555517e <+21>:    mov    %rax,-0x8(%rbp)
   0x0000555555555182 <+25>:    xor    %eax,%eax
   0x0000555555555184 <+27>:    movq   $0x0,-0x70(%rbp)
   0x000055555555518c <+35>:    movq   $0x0,-0x68(%rbp)
   0x0000555555555194 <+43>:    movq   $0x0,-0x60(%rbp)
   0x000055555555519c <+51>:    movq   $0x0,-0x58(%rbp)
   0x00005555555551a4 <+59>:    movq   $0x0,-0x50(%rbp)
   0x00005555555551ac <+67>:    movq   $0x0,-0x48(%rbp)
   0x00005555555551b4 <+75>:    movq   $0x0,-0x40(%rbp)
   0x00005555555551bc <+83>:    movq   $0x0,-0x38(%rbp)
   0x00005555555551c4 <+91>:    movq   $0x0,-0x30(%rbp)
   0x00005555555551cc <+99>:    movq   $0x0,-0x28(%rbp)
   0x00005555555551d4 <+107>:   movq   $0x0,-0x20(%rbp)
   0x00005555555551dc <+115>:   movq   $0x0,-0x18(%rbp)
   0x00005555555551e4 <+123>:   movl   $0x0,-0x10(%rbp)
=> 0x00005555555551eb <+130>:   movzbl -0x70(%rbp),%eax
   0x00005555555551ef <+134>:   movsbl %al,%eax
   0x00005555555551f2 <+137>:   mov    %eax,%esi
   0x00005555555551f4 <+139>:   lea    0xe09(%rip),%rdi        # 0x555555556004
   0x00005555555551fb <+146>:   mov    $0x0,%eax
   0x0000555555555200 <+151>:   callq  0x555555555070 <printf@plt>
   0x0000555555555205 <+156>:   mov    $0x0,%eax
   0x000055555555520a <+161>:   mov    -0x8(%rbp),%rdx
(gdb) q

$ gcc -g 1.c
$ gdb ./a.out
(gdb) r

Breakpoint 1, main () at 1.c:3
3       {
(gdb) n
4               char a[100] = {0};
(gdb)
5               printf("%d\n", a[0]);
(gdb) p a
$1 = '\000' <repeats 99 times>

Reply via email to