From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10885 invoked by alias); 9 Aug 2002 22:10:20 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 10878 invoked from network); 9 Aug 2002 22:10:19 -0000 Received: from unknown (HELO jackfruit.Stanford.EDU) (171.64.38.136) by sources.redhat.com with SMTP; 9 Aug 2002 22:10:19 -0000 Received: (from carlton@localhost) by jackfruit.Stanford.EDU (8.11.6/8.11.6) id g79MAJa25588; Fri, 9 Aug 2002 15:10:19 -0700 From: David Carlton MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15700.15818.829204.767503@jackfruit.Stanford.EDU> Date: Fri, 09 Aug 2002 15:10:00 -0000 To: gdb Subject: DWARF-2, static data members Cc: carlton@math.stanford.edu X-SW-Source: 2002-08/txt/msg00082.txt.bz2 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