FAIL: gcc (GCC) 4.5.0 20100202 (experimental)
FAIL: gcc-4.4.3-4.fc12.x86_64

 <2><c2>: Abbrev Number: 8 (DW_TAG_variable)
    <c3>   DW_AT_name        : x        
    <cb>   DW_AT_location    : 0x92     (location list)
    00000092 0000000000400509 000000000040050f (DW_OP_reg0)
    00000092 0000000000400510 0000000000400517 (DW_OP_lit0; DW_OP_stack_value)
    00000092 <End of list>
  40050b:       e8 d8 fe ff ff          callq  4003e8 <al...@plt>
  400510:       31 c0                   xor    %eax,%eax

Why is "x" valid on 40050b, 40050c, 40050d, 40050e but optimized-out on 40050f?
:-)

Unfortunately GDB pretends exactly this PC-1 address at the caller frames.

DWARF3 Page 26:
2. An ending address offset. [...] It marks the first address past the end of
the address range over which the location is valid.

The bug is introduced by revision 151312 dwarf2out.c line:
          sprintf (loclabel, "%s-1", last_label);

which causes:

(gdb) s
alarm () at ../sysdeps/unix/syscall-template.S:82
82      T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS)
(gdb) up
#1  0x0000000000400510 in main (argc=<value optimized out>, argv=<value
optimized out>)
    at /home/jkratoch/t/zero.c:9
9         alarm (x);
(gdb) p/x $pc
$1 = 0x400510
(gdb) p x
$2 = <value optimized out>

after a fix:
          sprintf (loclabel, "%s", last_label);
the loclist is now:
    00000092 0000000000400509 0000000000400510 (DW_OP_reg0)
    00000092 0000000000400510 0000000000400517 (DW_OP_lit0; DW_OP_stack_value)
    00000092 <End of list>
and GDB prints:
(gdb) p x
$2 = 1804289383

Compiled this testcase with -Wall -g -O2; #includes were not inlined but I hope
it is not a problem for this Bug.

#include <stdlib.h>
#include <unistd.h>

int
main (int argc, char **argv)
{
  int x = rand ();

  alarm (x);

  x = 0;

  return x;
}


-- 
           Summary: Location list ending address should not be one-less
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jan dot kratochvil at redhat dot com
GCC target triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42939

Reply via email to