[Bug debug/102441] New: Incorrect location list in debug info

liyd2021 at gmail dot com gcc-bugzilla@gcc.gnu.org
Wed Sep 22 06:36:33 GMT 2021


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

            Bug ID: 102441
           Summary: Incorrect location list in debug info
           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 with gdb (Ubuntu 20.04.2)

(terminal) $ cat simple.c && gcc -g -O2 simple.c
void __attribute__((noipa)) not_opt_this(int *r) {}

int __attribute__((noinline)) foo(int x) {
    int r = 0;
    not_opt_this(&r);
    return r;
}

int main (void) {
    return foo (10);
}
--------------------

(terminal) $ cat run.gdb
b foo
b 5
r
c

(terminal) $ gdb -x run.gdb a.out
Breakpoint 1 at 0x401190: file simple.c, line 4.
Breakpoint 2 at 0x4011a1: file simple.c, line 5.

Breakpoint 1, foo (x=10) at simple.c:4
4           int r = 0;

Breakpoint 2, foo (x=-9492) at simple.c:5 <-- **BUG**: x should be 10
5           not_opt_this(&r);

--------------------
debug info and assembly:

<2><88>: Abbrev Number: 7 (DW_TAG_formal_parameter)
    <89>   DW_AT_name        : x
    <8b>   DW_AT_decl_file   : 1
    <8c>   DW_AT_decl_line   : 3
    <8d>   DW_AT_decl_column : 39
    <8e>   DW_AT_type        : <0x5f>
    <92>   DW_AT_location    : 0x4 (location list)
    <96>   DW_AT_GNU_locviews: 0x0

Contents of the .debug_loc section:

    Offset   Begin            End              Expression

    00000000 v000000000000000 v000000000000000 location view pair
    00000002 v000000000000000 v000000000000000 location view pair

    00000004 v000000000000000 v000000000000000 views at 00000000 for:
             0000000000401190 00000000004011a5 (DW_OP_reg5 (rdi))
    00000017 v000000000000000 v000000000000000 views at 00000002 for:
             00000000004011a5 00000000004011af (DW_OP_GNU_entry_value:
(DW_OP_reg5 (rdi)); DW_OP_stack_value)
    0000002d <End of list>

0x401190 <foo>                  sub    $0x18,%rsp
0x401194 <foo+4>                lea    0xc(%rsp),%rdi
0x401199 <foo+9>                movl   $0x0,0xc(%rsp)
0x4011a1 <foo+17>               callq  0x401180 <not_opt_this>
0x4011a6 <foo+22>               mov    0xc(%rsp),%eax
0x4011aa <foo+26>               add    $0x18,%rsp
0x4011ae <foo+30>               retq

Debug info shows x in register %rdi, but %rdi was clobbered after 0x401194.


More information about the Gcc-bugs mailing list