This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA] Fix PR gdb/11702, printing of static const member variables
On Mon, 28 Jun 2010 20:26:12 +0200, Doug Evans wrote:
> On Mon, Jun 28, 2010 at 4:02 AM, Jan Kratochvil
> <jan.kratochvil@redhat.com> wrote:
> > On Sun, 27 Jun 2010 20:24:42 +0200, Doug Evans wrote:
> >> btw, the dwarf4 standard, as I read it, says static member variables are
> >> identified by having DW_AT_external. Â[4.1 Data Object Entries]
> >> However, dwarf2_add_field is calling die_is_declaration.
> >
> > echo 'class C { static const float i = 1; } c;'|g++ -c -o 1.o -Wall -g -x c++ -
> >  Â< c>  DW_AT_producer  Â: (indirect string, offset: 0x11): GNU C++ 4.6.0 20100628 (experimental)
> > Â<2><33>: Abbrev Number: 3 (DW_TAG_member)
> >  Â<34>  DW_AT_name    Â: i
> >  Â<38>  DW_AT_type    Â: <0x45>
> >  Â<3c>  DW_AT_external  Â: 1
> > Â Â<3d> Â DW_AT_accessibility: 3 Â Â Â (private)
> > Â Â<3e> Â DW_AT_declaration : 1
> > Â Â<3f> Â DW_AT_const_value : 4 byte block: 0 0 80 3f
> >
> > Isn't it primarily a bug in GCC? ÂThere is no other DIE for `i' and it is
> > a complete definition so there is no place for DW_AT_declaration there.
> >
> > Just such GCC change will be incompatible with existing GDBs, maybe to make
> > the GCC change only for -gdwarf-4 upwards which is incompatible with older
> > GDBs anyway?
>
> I'm not sure I follow.
> If all the GCC versions we care about are also adding DW_AT_external
> to the DIE, gdb *could* check for it instead of die_is_declaration,
> right? Or am I missing something?
Your referenced text
# DWARF-4: 4.1 Data Object Entries
# The definitions of C++ static data members of structures or classes are
# represented by variable entries flagged as external. Both file static and
# local variables in C and C++ are represented by non-external variable entries.
IMO more describes when `external' is present. It does not describe that
member is `static' would be determined by presence of the `external' attribute.
------------------------------------------------------------------------------
There are several problems to solve:
(a) How should the DWARF look from a blue sky compiler written from scratch,
according to the latest DWARF standard.
(b) How should GDB determine it is a `static' field.
(c) How should be (b) made backward and forward compatible with current GCC
versions.
=> means "specifies how should be"
(b) must not => (a)
(c) must not => (a)
(a) => (b)
(b) => (c)
------------------------------------------------------------------------------
So for the (a) point: I believe GCC should not produce DW_AT_declaration when
the same DIE has DW_AT_const_value.
(Also checked GCC source that it really does not emit it intentionally and it
may be more a bug.) That's all.
For the (b) point - GDB should check missing DW_AT_data_member_location.
(Just guessed - is it OK? I have not tried to implement it.)
(c) I guess the (b) rule works even with current GCC output, no special
compatibility cludge is needed.
Thanks,
Jan