[Dwarf-Discuss] name lookup w/ using directives

Michael Eager eager@eagercon.com
Wed Aug 20 18:17:18 GMT 2008


Kendrick Wong wrote:
> 
> In my example, I've used a search method which would search the current 
> scope, then the names introduced by using directive, then the enclosing 
> scopes.  That's how A::B::a is arrived at.
> 
>  > If the successively enclosing scopes are searched for "a", it is not
>  > found in "func", then a search within namespace "C" does find A::C::a.
>  > What search method would skip searching the enclosing namespace?
> In your example, enclosing scopes are searched first, consider this:
> int a = 1;
> namespace A {
>   namespace B {
>     int a = 2;
>   }
>   namespace C {
>     int fun () {
>       using namespace B;
>       return a;     // returns A::B::a
>     }
>   }
> }
> 
> Searching successively enclosing scope would yield ::a, but compiler 
> would yield A::B::a.

I find the C++ name resolution process less than intuitively clear.  :-)
You need to search namespaces which are inserted into the current scope
by the "using namespace" directive.

If your debugger is stopped at the return in fun(), then you need to
search within the current scope (that of the function) for "a", where
it isn't found, then namespace B, where it is found.  The search of
namespace B is simple in this case, but it may involve searches of
the symbols that namespace B inherits from its parent scope(s).

>  > There are a number of quirks in C++ name resolution.  But I thought
>  > that DWARF did provide the debugger with the same structural info that
>  > the compiler uses in this process.
> Yes, DWARF does capture the same structural info, but it does not 
> capture how compiler use this information to perform name searching. 

The method used to perform name resolution is defined in the C++ standard.
Both the compiler and debugger must use the same method.  Since there is
no variability in how to perform this name search, there is no need for
DWARF to describe how it is done.

>  Arguably, this logic can be embedded within the debugger, but then it 
> would have to derive where the enclosing namespace and the using 
> namespace intersect, to figure out the correct point to introduce the 
> using directive.

Correct.  The place where the using directive appears in described in
the DWARF description of the class.

-- 
Michael Eager	 eager at eagercon.com
1960 Park Blvd., Palo Alto, CA 94306  650-325-8077




More information about the Dwarf-discuss mailing list