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

            Bug ID: 90279
           Summary: DW_AT_location missing for struct-based Variable
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: daniel.penning at embeff dot com
  Target Milestone: ---

------------------------------------------------
struct StrongType {
        explicit StrongType(int val) : m_value(val) { }
        int m_value;
};

StrongType Square(StrongType val) {
        return StrongType{val.m_value * val.m_value};
}

int EvalDwarfStrong(int var) {
        StrongType strongArg{var};
        StrongType strongRes = Square(strongArg);
        return strongRes.m_value;
}
------------------------------------------------

gcc -Og -g
dwarfdump outputs the following information for the strongArg variable:

< 2><0x000000a6>      DW_TAG_variable
                        DW_AT_name                  strongArg
                        DW_AT_decl_file             0x00000001
<SystemSpecific>/DwarfStrong.cpp
                        DW_AT_decl_line             0x0000000b
                        DW_AT_type                  <0x0000002d>



There is no DW_AT_location specified, so a debugger will not be able to display
its value.
This is not a problem-per-se with the struct since the DWARF output for the
Square() function argument is using a correct DW_AT_location.
The compiler is not inlining the function call with -Og so the variable will be
available right before the function call to Square().
Using the same code, but with a plain int instead of the struct-wrapper yields
the desired output:

-----------------------------------------------------
int Square(int val) {
        return val*val;
}

int EvalDwarfUnsafe(int var) {
        int unsafeArg{var};
        int unsafeRes = Square(unsafeArg);
        return unsafeRes;
}


< 2><0x00000061>      DW_TAG_variable
                        DW_AT_name                  unsafeArg
                        DW_AT_decl_file            
0x00000001<SystemSpecific>/DwarfUnsafe.cpp
                        DW_AT_decl_line             0x00000006
                        DW_AT_type                  <0x00000093>
                        DW_AT_location              <loclist at offset
0x00000039 with 2 entries follows>
                        [ 0]< offset pair low-off : 0x00000006 addr  0x00000006
high-off  0x0000000a addr 0x0000000a>DW_OP_reg5
                        [ 1]< offset pair low-off : 0x0000000a addr  0x0000000a
high-off  0x0000000d addr 0x0000000d>DW_OP_GNU_entry_value 0x00000001 contents
0x55 DW_OP_stack_value

Reply via email to