http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51410
Bug #: 51410 Summary: duplicate variable DIE Classification: Unclassified Product: gcc Version: 4.6.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: debug AssignedTo: unassig...@gcc.gnu.org ReportedBy: m...@gcc.gnu.org CC: tro...@redhat.com This used to confuse systemtap, it has been fixed by searching the symbol table to find the address of a variable if no location description is available if the var DIE is marked external. It can certainly be argued that systemtap should just search harder and find the other var DIE that does contain a location description. But it sure is confusing IMHO. Given the following source code: int x; int main(int argc, char **argv) { return x; } compiled with gcc (GCC) 4.6.1 20110908 (Red Hat 4.6.1-9) $ gcc -g -O2 -o /tmp/x x.c produces the following .debug_info: DWARF section [28] '.debug_info' at offset 0x6a5: [Offset] Compilation unit at offset 0: Version: 3, Abbreviation section offset: 0, Address size: 4, Offset size: 4 [ b] compile_unit producer (strp) "GNU C 4.6.1 20110908 (Red Hat 4.6.1-9)" language (data1) ISO C89 (1) name (string) "x.c" comp_dir (strp) "/home/mark/src/tests" ranges (data4) range list [ 0] low_pc (addr) 0000000000 entry_pc (addr) 0000000000 stmt_list (data4) 0 [ 29] subprogram external (flag) Yes name (strp) "main" decl_file (data1) 1 decl_line (data1) 3 prototyped (flag) Yes type (ref4) [ 61] low_pc (addr) 0x080482e0 <main> high_pc (addr) 0x080482e6 frame_base (block1) [ 0] call_frame_cfa sibling (ref4) [ 61] [ 44] formal_parameter name (strp) "argc" decl_file (data1) 1 decl_line (data1) 3 type (ref4) [ 61] location (block1) [ 0] fbreg 0 [ 52] formal_parameter name (strp) "argv" decl_file (data1) 1 decl_line (data1) 3 type (ref4) [ 68] location (block1) [ 0] fbreg 4 [ 61] base_type byte_size (data1) 4 encoding (data1) signed (5) name (string) "int" [ 68] pointer_type byte_size (data1) 4 type (ref4) [ 6e] [ 6e] pointer_type byte_size (data1) 4 type (ref4) [ 74] [ 74] base_type byte_size (data1) 1 encoding (data1) signed_char (6) name (strp) "char" [ 7b] variable name (string) "x" decl_file (data1) 1 decl_line (data1) 1 type (ref4) [ 61] external (flag) Yes declaration (flag) Yes [ 86] variable name (string) "x" decl_file (data1) 1 decl_line (data1) 1 type (ref4) [ 61] external (flag) Yes location (block1) [ 0] addr 0x8049634 <x> Note that there are two variable DIEs for x, 7b and 86, neither of which is references in the rest of the CU. Since 86 doesn't refer to 7b, it isn't clear to me how a consumer can know this is the same variable. In any case it seems redundant to have both, even if the consumer is supposed to discard the one marked as declaration. This isn't an issue for static variables, which will have only one var DIE. It is also a regression compared to gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-51) which would produce only one variable DIE for x.