Discussion:
DW_AT_specification: long ago GDB change
Jim Blandy
2004-04-15 05:17:23 UTC
Permalink
Back in 1999, you posted this patch:

http://sources.redhat.com/ml/gdb-patches/1999-q4/msg00325.html

Do you know why you tested for the presence of DW_AT_specification, as
well as DW_AT_declaration?

I can't think of a case where a die would be a declaration, but also
refer to a specification; since DW_AT_specification generally points
from definitions to previous declarations, I'd rather expect
specifications to point at declarations. And even if a declaration
did have a specification, it would still be a declaration.

Looking at the only code in gcc/dwarf2out.c that adds
DW_AT_specification attributes to dies supports this:

/* Add an AT_specification attribute to a DIE, and also make the back
pointer from the specification to the definition. */

static inline void
add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
{
add_AT_die_ref (die, DW_AT_specification, targ_die);
if (targ_die->die_definition)
abort ();
targ_die->die_definition = die;
}

I guess if there were several declarations chained together,
eventually pointing to a definition, then the intermediate dies could
have both attributes. Does this happen?
Jason Merrill
2004-04-15 13:51:05 UTC
Permalink
Post by Jim Blandy
http://sources.redhat.com/ml/gdb-patches/1999-q4/msg00325.html
Do you know why you tested for the presence of DW_AT_specification, as
well as DW_AT_declaration?
I can't think of a case where a die would be a declaration, but also
refer to a specification; since DW_AT_specification generally points
from definitions to previous declarations, I'd rather expect
specifications to point at declarations. And even if a declaration
did have a specification, it would still be a declaration.
Yes. IIRC, the issue is that dwarf_attr looks through the
DW_AT_specification link, so it will find a DW_AT_declaration attribute in
the definition. Also looking for DW_AT_specification allows us to avoid
that false positive for the test.

Jason
Jim Blandy
2004-04-15 22:19:17 UTC
Permalink
Post by Jason Merrill
Post by Jim Blandy
http://sources.redhat.com/ml/gdb-patches/1999-q4/msg00325.html
Do you know why you tested for the presence of DW_AT_specification, as
well as DW_AT_declaration?
I can't think of a case where a die would be a declaration, but also
refer to a specification; since DW_AT_specification generally points
from definitions to previous declarations, I'd rather expect
specifications to point at declarations. And even if a declaration
did have a specification, it would still be a declaration.
Yes. IIRC, the issue is that dwarf_attr looks through the
DW_AT_specification link, so it will find a DW_AT_declaration attribute in
the definition. Also looking for DW_AT_specification allows us to avoid
that false positive for the test.
You're right. Eeeew.

It's clearly wrong to follow DW_AT_specification and return the value
of the specification's DW_AT_declaration attribute. For most
attributes, though, that's the right behavior.

Here are the attributes I see that we shouldn't search for in dies
referenced by DW_AT_specification, but which are reasonable to look
for in dies referred to by DW_AT_abstract_origin:

- DW_AT_declaration
- DW_AT_decl_column
- DW_AT_decl_file
- DW_AT_decl_line


Here are attributes which apply only to a specific die, and should
never be searched for on any referenced DIE:

- DW_AT_sibling

I don't think that needs to be addressed; it's only relevant when
reading dies anyway.

I'll try to put together a patch for this.
Jason Merrill
2004-04-16 12:49:16 UTC
Permalink
Post by Jim Blandy
Here are the attributes I see that we shouldn't search for in dies
referenced by DW_AT_specification, but which are reasonable to look
- DW_AT_declaration
- DW_AT_decl_column
- DW_AT_decl_file
- DW_AT_decl_line
I disagree about the other three; if the definition has different source
coordinates, it will have the attributes. If it doesn't, there's no reason
to emit them again, and we should look them up in the declaration.

Jason
Jim Blandy
2004-04-16 21:26:00 UTC
Permalink
Post by Jason Merrill
Post by Jim Blandy
Here are the attributes I see that we shouldn't search for in dies
referenced by DW_AT_specification, but which are reasonable to look
- DW_AT_declaration
- DW_AT_decl_column
- DW_AT_decl_file
- DW_AT_decl_line
I disagree about the other three; if the definition has different source
coordinates, it will have the attributes. If it doesn't, there's no reason
to emit them again, and we should look them up in the declaration.
Yeah, that makes sense to me. I'd forgotten about the peeking through
DW_AT_specification behavior for DW_AT_declaration; thanks for the kick
in the right direction.
Okay. So then DW_AT_declaration is the only thing that needs to be
blocked.

Loading...