This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

DWARF-2, static data members


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]