Bug 29628

Summary: unused argc/argv missing their DW_AT_location
Product: gcc Reporter: Jan Kratochvil <jkratochvil>
Component: debugAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: dodji, gcc-bugs
Priority: P3    
Version: unknown   
Target Milestone: ---   
Host: Target: i686-pc-linux-gnu
Build: Known to work:
Known to fail: Last reconfirmed:

Description Jan Kratochvil 2006-10-28 20:13:54 UTC
`main' function (the function with specific prologue/epilogue) is missing DWARF `DW_AT_location' for its `argc' and `argv' on 32-bit targets - only if these arguments are never unused.

affected: x86_64-redhat-linux with -m32, i386-redhat-linux
not affected: x86_64-redhat-linux (-m64)

32-bit broken for: gcc-4.1.1, SVN snapshot 4.3.0
always works: gcc-3.4.6

It causes gdb(1) to hide the arguments during backtrace:
#0  main () at test.c:3


correct [i386]:
echo 'int main (int argc, char **argv) { return argc + (int) argv; }' >main.c ;gcc -o main.o main.c -ggdb3;readelf -a --debug main.o|grep -A5 -w argc

incorrect [i386]:
echo 'int main (int argc, char **argv) { return 0; }' >main.c ;gcc -o main.o main.c -ggdb3;readelf -a --debug main.o|grep -A5 -w argc


correct (gcc-3.4.6):
 <1><ee3>: Abbrev Number: 33 (DW_TAG_subprogram)
     DW_AT_sibling     : <f63>
     DW_AT_external    : 1
     DW_AT_name        : main
     DW_AT_decl_file   : 46
     DW_AT_decl_line   : 267
     DW_AT_prototyped  : 1
     DW_AT_type        : <c4>
     DW_AT_low_pc      : 0x8048c0f
     DW_AT_high_pc     : 0x8048e26
     DW_AT_frame_base  : 616    (location list)
 <2><f02>: Abbrev Number: 34 (DW_TAG_formal_parameter)
     DW_AT_name        : argc
     DW_AT_decl_file   : 46
     DW_AT_decl_line   : 267
     DW_AT_type        : <c4>
     DW_AT_location    : 2 byte block: 91 0     (DW_OP_fbreg: 0)
 <2><f12>: Abbrev Number: 34 (DW_TAG_formal_parameter)
     DW_AT_name        : argv
     DW_AT_decl_file   : 46
     DW_AT_decl_line   : 267
     DW_AT_type        : <f63>
     DW_AT_location    : 2 byte block: 91 4     (DW_OP_fbreg: 4)

incorrect (gcc-4.1.1; appropriately for SVN snapshot - ~4.3.0):
 <1><64>: Abbrev Number: 2 (DW_TAG_subprogram)
     DW_AT_external    : 1
     DW_AT_name        : main
     DW_AT_decl_file   : 1
     DW_AT_decl_line   : 2
     DW_AT_prototyped  : 1
     DW_AT_type        : <9b>
     DW_AT_low_pc      : 0x8048324
     DW_AT_high_pc     : 0x804833d
     DW_AT_frame_base  : 0      (location list)
     DW_AT_sibling     : <9b>
 <2><82>: Abbrev Number: 3 (DW_TAG_formal_parameter)
     DW_AT_name        : argc
     DW_AT_decl_file   : 1
     DW_AT_decl_line   : 1
     DW_AT_type        : <9b>
 <2><8e>: Abbrev Number: 3 (DW_TAG_formal_parameter)
     DW_AT_name        : argv
     DW_AT_decl_file   : 1
     DW_AT_decl_line   : 1
     DW_AT_type        : <a2>



dwarf2.out.c mem_loc_descriptor () GET_CODE (rtl):
`case REG:' for i386 `argc'; it will fail on:
  if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
Checked there:
        REGNO (rtl) == 61   /* Therefore pseudoreg.  */
        ORIGINAL_REGNO (rtl) == REGNO (rtl)
        reg_renumber [61] == -1

On i386 with the arguments used it is fine as:
        REGNO (rtl) == 1   /* Therefore hard register.  */

On x86_64 it goes the `case PLUS:' way, not `case REG:'.


Could you advice where to find the location information for pseudoregisters there?
Comment 1 Jakub Jelinek 2006-10-30 16:11:47 UTC
This is caused by the stack realignment in i?86 main, the way it is currently implemented is that address of first argument is loaded into %ecx and
then the stack is realigned.  The pseudo register which shows in the
argument's RTL is that cfun->machine->force_align_arg_pointer (aka %ecx)
copied into a pseudo.
Comment 2 Dodji Seketeli 2008-10-13 14:23:45 UTC
Hello,

I can't reproduce this neither on 4.3 nor trunk branch.
In both branch, the variables have the DW_AT_location attribute.
Please see below the attached dwarf output.
Comment 3 Jan Kratochvil 2008-10-13 14:34:58 UTC
Fedora gcc-4.3.2-6.x86_64 with -m32 is still buggy as described in the Comment 0.
But HEAD works OK now (-m32) so closing, thanks for the test:
GNU C (GCC) version 4.4.0 20081007 (experimental) (x86_64-unknown-linux-gnu)
	compiled by GNU C version 4.4.0 20081007 (experimental), GMP version 4.2.2, MPFR version 2.3.1.