Re: [RFA 2/4] dwarf2_physname

Keith Seitz
2010-02-01T21:52:40Z

On 02/01/2010 11:39 AM, Daniel Jacobowitz wrote:
> DW_AT_specification is present for many variables in namespaces
> (at least in current GCC output). But what significance does it
> actually have? Can you explain the check above in terms of the DWARF
> standard? If not, I don't think it's right.

I don't know if what gcc is doing is proper DWARF or not, but I don't
see any indication on reading the DWARF3 spec that it is.

If I may use namespace.exp as an example:

namespace
{
namespace G
{
int Xg;
};
};

For this code, gcc will output a type-like information DIE tree, telling
us ONLY about the composition of the anonymous namespace with namespace
G and variable Xg. Later gcc gives us a DIE with DW_AT_location (to
continue my (poor) type analogy: an instance of the variable). To
describe this DIE, we also get DW_AT_specification and nothing more.
Just DW_AT_location and DW_AT_specification.

If we do not follow DW_AT_specification, dwarf2_physname will put the
variable Xg in the global namespace instead of "(anonymous
namespace)::G::Xg", which is where it really is defined.

> DW_AT_specification just says that there is a specification of this
> variable in another DIE. The same variable could be written with
> or without it.

In the case where DW_AT_specification is omitted, the physname
information is contained within the DIE's immediate ancestry. I would
expect to see, e.g.,

DW_TAG_namespace
-- DW_AT_name
-- DW_TAG_namespace
-- DW_AT_name
-- DW_TAG_variable
-- DW_AT_name
-- DW_AT_location

as opposed to (the below is what we actually get from gcc)

DW_TAG_namespace
-- DW_AT_name
-- DW_TAG_namespace
-- DW_AT_name
-- DW_TAG_variable
-- DW_AT_name
...
DW_AT_variable
-- DW_AT_specification (points to DW_TAG_variable above)
-- DW_AT_location

Keith