Tested on: GNU C++ 4.4.0 20090323 (experimental) Testcase: ------------------------------------------------------------------------------ namespace A { static int var2 = 2; }
int func (void) { using A::var2; return var2; } ------------------------------------------------------------------------------ will generate (reduced): <1><2d>: Abbrev Number: 2 (DW_TAG_subprogram) <2f> DW_AT_name : (indirect string, offset: 0x42): func <3d> DW_AT_low_pc : 0x0 <45> DW_AT_high_pc : 0xc <4d> DW_AT_frame_base : 0x0 (location list) <2><55>: Abbrev Number: 3 (DW_TAG_lexical_block) <56> DW_AT_low_pc : 0x4 <5e> DW_AT_high_pc : 0xa <3><66>: Abbrev Number: 4 (DW_TAG_imported_declaration) <69> DW_AT_import : <0x7f> [Abbrev Number: 7 (DW_TAG_variable)] <1><76>: Abbrev Number: 6 (DW_TAG_namespace) <77> DW_AT_name : A <2><7f>: Abbrev Number: 7 (DW_TAG_variable) <80> DW_AT_name : (indirect string, offset: 0x34): var2 <84> DW_AT_decl_file : 1 <85> DW_AT_decl_line : 3 <86> DW_AT_type : <0x6f> <8a> DW_AT_declaration : 1 <2><8b>: Abbrev Number: 7 (DW_TAG_variable) <8c> DW_AT_name : (indirect string, offset: 0x34): var2 <84> DW_AT_decl_file : 1 <85> DW_AT_decl_line : 3 <92> DW_AT_type : <0x6f> <96> DW_AT_declaration : 1 <1><98>: Abbrev Number: 8 (DW_TAG_variable) <99> DW_AT_specification: <0x8b> <9d> DW_AT_location : 9 byte block: 3 0 0 0 0 0 0 0 0 (DW_OP_addr: 0) You can see the code references the <7f> "var" instance but DW_AT_location is given by the <98> completion only for the <8b> "var" instance. Also <7f> and <8b> have a name conflict as being in the same naming scope. This problem causes a wrong evaluation by Archer archer-keiths-expr-cumulative branch (which is IMO right) for the more complex testcase - as it cannot find the right DW_AT_location there: ------------------------------------------------------------------------------ # archer-keiths-expr-cumulative=35ca449e9f1a4cd477df644f717bbe4e3362c486/gdb -q ./outer (gdb) l 1 1 #include <stdlib.h> 2 3 namespace A 4 { 5 static int var = 2; 6 } 7 8 int 9 main (void) 10 { 11 int var = 1; 12 13 if (var != 1) /* var-is-1 */ 14 abort (); 15 16 { 17 using A::var; 18 19 if (var != 2) /* var-is-2 */ 20 abort (); 21 } 22 23 return 0; /* break-here */ 24 } (gdb) b 13 Breakpoint 1 at 0x4005a7: file outer.C, line 13. (gdb) r Starting program: /tmp/outer Breakpoint 1, main () at outer.C:13 13 if (var != 1) /* var-is-1 */ (gdb) p var $1 = 1 (gdb) adv 19 main () at outer.C:19 19 if (var != 2) /* var-is-2 */ (gdb) p var $2 = 1 ^^^^^^ Wrong GDB evaluation. (gdb) adv 23 main () at outer.C:23 23 return 0; /* break-here */ (gdb) q ------------------------------------------------------------------------------ -- Summary: Duplicite C++ DW_TAG_variable breaking its DW_AT_location resolution Product: gcc Version: 4.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: debug AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jan dot kratochvil at redhat dot com GCC target triplet: x86_64-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39524