* DWARF-2, static data members
@ 2002-08-09 15:10 David Carlton
2002-08-13 13:48 ` Jim Blandy
0 siblings, 1 reply; 4+ messages in thread
From: David Carlton @ 2002-08-09 15:10 UTC (permalink / raw)
To: gdb; +Cc: carlton
I was looking through dwarf2read.c and through the DWARF 2 standard (I
have a PDF of an "Industry Review Draft" from July 27, 1993, and I've
also looked at the PDF for the DWARF 3 draft 7 from October 29, 2001),
and it seems, judging from GDB's code, GCC and GDB both have the wrong
idea about what tags should be present in static data members of C++
classes.
Specifically, the code in read_structure_scope() and
dwarf2_add_field() (both within dwarf2read.c) both treat static data
members as being characterized by children that have the tag
DW_TAG_variable. But I don't see that within the relevant section of
the DWARF 2 standard (5.5 Structure, Union, and Class Type Entries):
e.g. 5.5.4 Structure Data Member Entries simply says that
A data member (as opposed to a member function) is represented by a
debugging information with the tag DW_TAG_member.
and there's no indication that that doesn't apply to static data
members. Or in 5.5.1 General Structure Description, it says in a
comment that
Data member declarations occuring within the declaration of a
structure, union or class type are considered to be "definitions" of
those members, with the exception of C++ "static" data members,
whose definitions appear outside of the declaration of the enclosing
structure, union or class type.
From this, it seems to me that static data members should be
represented by children of the class that have the tag DW_TAG_member
but that have the flag DW_AT_declaration set.
Also relevant is the section 4.1 Data Object Entries, which _does_
talk about DW_TAG_variable; what it says there is that
The definitions of C++ static data members of structures or classes
are represented by variable entries flagged as external.
Note here that it says "definitions"; the bit I previously quoted made
it clear that declarations occurring within a class _aren't_ the
definitions of the variables. And further on, we have
If the variable entry represents the defining declaration for a C++
static data member of a structure, class or union, the entry has a
DW_AT_specification attribute, whose value is a reference to the
debugging information entry representing the declaration of this
data member. The referenced entry will be a child of some class,
structure or union type entry.
Again, this makes it clear that the definition (which is presumably a
DW_TAG_variable) is different from the declaration (which is
presumably a DW_TAG_member). And I've gone through the DWARF 3 draft,
and it says the same thing.
Having said all that, when I run GDB on some code with static data
members that I'd compiled with GCC 3.1, the appropriate branches were
taken. Which means that either there's something I _really_ don't
understand about GDB's code (always a possibility!) or else GCC is
making the same misinterpretation and GDB.
Nonetheless, I think they should both be fixed. It seems to me that
the safe thing to do would be to modify GDB so that it treats members
that either are DW_TAG_variable or DW_TAG_member + DW_AT_declaration
as static data members; that way it will be safe both with code
compiled by current versions of GCC and by code compiled with
hypothetical future versions of GCC that have this misinterpretation
fixed (as well as other compilers out there that might do the right
thing). I'd be happy to try to make this change if other people agree
with me.
David Carlton
carlton@math.stanford.edu
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: DWARF-2, static data members
2002-08-09 15:10 DWARF-2, static data members David Carlton
@ 2002-08-13 13:48 ` Jim Blandy
2002-08-13 14:05 ` David Carlton
0 siblings, 1 reply; 4+ messages in thread
From: Jim Blandy @ 2002-08-13 13:48 UTC (permalink / raw)
To: David Carlton; +Cc: gdb
I agree with your reading. There should be *two* entries for a C++
static data member: one as a variable definition, DW_TAG_variable, at
the top level, and one as a member definition, DW_TAG_member, as a
child of the struct/class/union die.
This sort of corresponds to the way you have to actually declare a
static member in C++. In the class definition you say:
class C
{
static int foo;
}
and then somewhere else you must actually give the definition of C::foo:
int C::foo;
For what it's worth, the paragraph of the Dwarf 2 spec that
corresponds to paragraph 6. in Section 4.1 of Draft 3 rev 7 (what I
treat as authoritative for Dwarf 3) doesn't specify what tag the type
die's child is supposed to have. I guess the entire GNU toolchain
just guessed wrong.
> Having said all that, when I run GDB on some code with static data
> members that I'd compiled with GCC 3.1, the appropriate branches were
> taken. Which means that either there's something I _really_ don't
> understand about GDB's code (always a possibility!) or else GCC is
> making the same misinterpretation and GDB.
Have you run `readelf -wi' on the executable, or run GCC with
`-save-temps -dA' and looked at the .s file, to see what GCC is
actually generating? I think GCC does generate children of
struct/class types with the DW_TAG_variable tag.
> Nonetheless, I think they should both be fixed. It seems to me that
> the safe thing to do would be to modify GDB so that it treats members
> that either are DW_TAG_variable or DW_TAG_member + DW_AT_declaration
> as static data members; that way it will be safe both with code
> compiled by current versions of GCC and by code compiled with
> hypothetical future versions of GCC that have this misinterpretation
> fixed (as well as other compilers out there that might do the right
> thing). I'd be happy to try to make this change if other people agree
> with me.
That sounds right to me.
You might put together a fix for GCC, too --- dwarf2out.c is big, but
it doesn't seem too bad. This would allow you to actually test your
changes.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: DWARF-2, static data members
2002-08-13 13:48 ` Jim Blandy
@ 2002-08-13 14:05 ` David Carlton
2002-08-13 15:29 ` Jim Blandy
0 siblings, 1 reply; 4+ messages in thread
From: David Carlton @ 2002-08-13 14:05 UTC (permalink / raw)
To: Jim Blandy; +Cc: gdb
In article <vt2ofc6ze70.fsf@zenia.red-bean.com>, Jim Blandy
<jimb@zenia.red-bean.com> writes:
> I agree with your reading. There should be *two* entries for a C++
> static data member: one as a variable definition, DW_TAG_variable,
> at the top level, and one as a member definition, DW_TAG_member, as
> a child of the struct/class/union die.
Right. Though you can presumably skip the DW_TAG_variable entry if
you're compiling a file in which that variable never gets defined or
referred to. (E.g. if the file you're compiling includes a header
file defining a class that it uses, but the file you're compiling
doesn't happen to use that particular static member of the class
itself.)
> For what it's worth, the paragraph of the Dwarf 2 spec that
> corresponds to paragraph 6. in Section 4.1 of Draft 3 rev 7 (what I
> treat as authoritative for Dwarf 3) doesn't specify what tag the
> type die's child is supposed to have.
Good point: I'd missed that Dwarf 3 is more explicit there. Dwarf 2
seems to me to be explicit enough, in that the section on class
declarations that says that data members should have the DW_TAG_member
(with no exception for static data members), but it's a good thing
that Dwarf 3 makes that clearer.
> Have you run `readelf -wi' on the executable, or run GCC with
> `-save-temps -dA' and looked at the .s file, to see what GCC is
> actually generating? I think GCC does generate children of
> struct/class types with the DW_TAG_variable tag.
I'll have to look up what those arguments mean :-), but I did do g++
-S yesterday and went through the .s file by hand. (Fun, and
educational, though I don't plan to do it too often.) It really is
generating DW_TAG_variable tags instead of DW_TAG_member tags.
> You might put together a fix for GCC, too --- dwarf2out.c is big,
> but it doesn't seem too bad. This would allow you to actually test
> your changes.
I'll give it a look. I did submit a PR for GCC, so at least it's in
their bug database.
David Carlton
carlton@math.stanford.edu
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: DWARF-2, static data members
2002-08-13 14:05 ` David Carlton
@ 2002-08-13 15:29 ` Jim Blandy
0 siblings, 0 replies; 4+ messages in thread
From: Jim Blandy @ 2002-08-13 15:29 UTC (permalink / raw)
To: David Carlton; +Cc: gdb
David Carlton <carlton@math.stanford.edu> writes:
> > Have you run `readelf -wi' on the executable, or run GCC with
> > `-save-temps -dA' and looked at the .s file, to see what GCC is
> > actually generating? I think GCC does generate children of
> > struct/class types with the DW_TAG_variable tag.
>
> I'll have to look up what those arguments mean :-), but I did do g++
> -S yesterday and went through the .s file by hand. (Fun, and
> educational, though I don't plan to do it too often.) It really is
> generating DW_TAG_variable tags instead of DW_TAG_member tags.
Heh. Do try out -save-temps -dA. :)
> > You might put together a fix for GCC, too --- dwarf2out.c is big,
> > but it doesn't seem too bad. This would allow you to actually test
> > your changes.
>
> I'll give it a look. I did submit a PR for GCC, so at least it's in
> their bug database.
Sounds good.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-08-13 22:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-09 15:10 DWARF-2, static data members David Carlton
2002-08-13 13:48 ` Jim Blandy
2002-08-13 14:05 ` David Carlton
2002-08-13 15:29 ` Jim Blandy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox