DWARF 2 Problem.

Nitin Gupta niting@noida.hcltech.com
Mon Feb 4 04:41:00 GMT 2002


Test Program :
	int main() {
		int i = 0;
		{
			int k = i;
			int i = 4;
			printf("%d\n",k,i);
		}
	}

compiled with

$ gcc -v -gdwarf-2 t.c
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-81)
...
...


As per DWARF2.1 (Draft 6) Specs [Page 59 Point 11]. The scope of the
the variable "i" defined in lexical block starts after the initialization
statement of "i"[i=4]
 in inner lexical block. So when value of "i" is printed (during debugging)
in lexical 
block before initialization statement of "i" [i=4] it should be 0 (as in the
outer block).

A strange behavior is seen as a garbage value is output by debugger  when
the value 
 "i" is printed when control is stopped at  "int k=i". When the control is 
at the very next line "int i = 4" the value of the k is  0. The debugger
gets confused 
and refers to the location of "i" declared in the lexical block.

The problem seems to be in the DIE generated for "i" in the lexical block.
It is 
[as obtained by readelf ] 

<2><8c>: Abbrev Number: 4 (DW_TAG_lexical_block)
     DW_AT_low_pc      : 0x116c 4460
     DW_AT_high_pc     : 0x1186 4486
 <3><95>: Abbrev Number: 3 (DW_TAG_variable)
     DW_AT_name        : k
     DW_AT_decl_file   : 1
     DW_AT_decl_line   : 5
     DW_AT_type        : <af>
     DW_AT_location    : 2 byte block: 91 4     (DW_OP_fbreg: 4)
 <3><a1>: Abbrev Number: 3 (DW_TAG_variable)
     DW_AT_name        : i
     DW_AT_decl_file   : 1
     DW_AT_decl_line   : 6
     DW_AT_type        : <af>
     DW_AT_location    : 2 byte block: 91 8     (DW_OP_fbreg: 8)

The DIE of i should also have the attribute DW_AT_start_scope so that
the debugger in confused.

The same DIEs are generated by gcc version 3.1 20011017 (experimental)
though
I have not tried debugging the binary generated by it.

Is it the intended behavior? Please let me know if I'm missing 
something. 

Thanks and Best Regards.
Nitin.



More information about the Gcc-bugs mailing list