[Dwarf-Discuss] name lookup w/ using directives

Kendrick Wong kendrick at ca.ibm.com
Wed Aug 20 07:42:55 PDT 2008


While working with namespaces, I've ran into cases where there is no good 
way to determine the correct name lookup:

scenario A:
namespace A {
  namespace B {
    int a = 1;
  }
  namespace C {
    int func () {
      using namespace B;
      return a;     // returns A::B::a
    }
  }
}

Sample DWARF:
10$: DW_TAG_namespace
       DW_AT_name("A")
20$:   DW_TAG_namespace
         DW_AT_name("B")
30$:     DW_TAG_variable
           DW_AT_name("a")
40$:   DW_TAG_namespace
         DW_AT_name("C")
50$:     DW_TAG_subprogram
           DW_AT_name("func")
60$:       DW_TAG_imported_module
             DW_AT_import(reference to 20$)

If a debugger stops in func(), and asks to examine 'a'.  A debugger can 
try to search for 'a' within func(), failing that, it would look inside 
namespace B, and in this case, it finds A::B::a, which is the correct 'a' 
to find.

scenario B:
namespace A {
  namespace B {
    int a = 1;
  }
  namespace C {
    int a = 2;    // introduce A::C::a
    int func () {
      using namespace B;
      return a;     // returns A::C::a
    }
  }
}

Sample DWARF:
10$: DW_TAG_namespace
       DW_AT_name("A")
20$:   DW_TAG_namespace
         DW_AT_name("B")
30$:     DW_TAG_variable
           DW_AT_name("a")
40$:   DW_TAG_namespace
         DW_AT_name("C")
45$:     DW_TAG_variable         // introduce A::C::a
           DW_AT_name("a")
50$:     DW_TAG_subprogram
           DW_AT_name("func")
60$:       DW_TAG_imported_module
             DW_AT_import(reference to 20$)

If a debugger use the same name lookup technique as in scenario A, it's 
going to find A::B::a, which is incorrect.
I think debugger needs a little more help (in the form of additional DWARF 
info) to be able to perform the same name lookup as the compiler.  I do 
have a solution in my head to solve the problem as well, but I will wait 
until I get a confirmation that this is indeed a problem worth diving 
into.

Thanks,
Regards,


Kendrick Wong 
Common Debug Architecture 
C2/YGK/8200/MKM 
kendrick at ca.ibm.com 
Office:905-413-2865 Fax:905-413-4839 Tie:313-2865 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dwarfstd.org/private.cgi/dwarf-discuss-dwarfstd.org/attachments/20080820/f4306e6e/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 3113 bytes
Desc: not available
URL: <http://lists.dwarfstd.org/private.cgi/dwarf-discuss-dwarfstd.org/attachments/20080820/f4306e6e/attachment-0001.gif>


More information about the Dwarf-Discuss mailing list