Before DWARF5 there was no description of class variables (static data members) and gcc would emit a DW_TAG_member for the class variables as if the were non-static data members. DWARF5, section 5.7.7 Class Variable Entries, says they are represented by a DW_TAG_variable. GCC has the following in dwarf2out.c: /* For static data members, the declaration in the class is supposed to have DW_TAG_member tag in DWARF{3,4} and we emit it for compatibility also in DWARF2; the specification should still be DW_TAG_variable referencing the DW_TAG_member DIE. */ if (declaration && class_scope_p (context_die) && dwarf_version < 5) var_die = new_die (DW_TAG_member, context_die, decl); else var_die = new_die (DW_TAG_variable, context_die, decl); if (origin != NULL) add_abstract_origin_attribute (var_die, origin); This means that when building with -gdwarf-5 there no longer is a DW_TAG_member for static data members, but an DW_TAG_variable (which can be optimized away when not referenced). This causes the following testsuite failures: FAIL: gdb.base/ptype-offsets.exp: ptype/o static_member FAIL: gdb.cp/constexpr-field.exp: print y FAIL: gdb.cp/m-static.exp: static const int initialized nowhere (print field) FAIL: gdb.cp/m-static.exp: ptype test4.nowhere FAIL: gdb.cp/m-static.exp: print test4.nowhere.nowhere FAIL: gdb.cp/m-static.exp: static const int initialized nowhere (whole struct) FAIL: gdb.cp/m-static.exp: static const int initialized in class definition FAIL: gdb.cp/m-static.exp: static const float initialized in class definition FAIL: gdb.cp/m-static.exp: info variable everywhere FAIL: gdb.cp/namespace.exp: print C::OtherFileClass::cOtherFileClassVar FAIL: gdb.cp/namespace.exp: print ::C::OtherFileClass::cOtherFileClassVar FAIL: gdb.cp/namespace.exp: ptype ::C::OtherFileClass typedefs FAIL: gdb.cp/namespace.exp: ptype OtherFileClass typedefs FAIL: gdb.cp/pr-574.exp: PR gdb/574 FAIL: gdb.cp/pr9167.exp: p b FAIL: gdb.cp/templates.exp: ptype T5<int> FAIL: gdb.cp/templates.exp: ptype t5i
(In reply to Mark Wielaard from comment #0) > FAIL: gdb.base/ptype-offsets.exp: ptype/o static_member The member isn't defined; this works: diff --git a/gdb/testsuite/gdb.base/ptype-offsets.cc b/gdb/testsuite/gdb.base/ptype-offsets.cc index ddb009f1ae5..b686c9bdc3a 100644 --- a/gdb/testsuite/gdb.base/ptype-offsets.cc +++ b/gdb/testsuite/gdb.base/ptype-offsets.cc @@ -185,6 +185,8 @@ struct static_member int abc; }; +static_member static_member::Empty; + int main (int argc, char *argv[]) { > FAIL: gdb.cp/constexpr-field.exp: print y This one is weird, the constexpr fields aren't described in the DWARF. Maybe a test change is needed, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90526#c1 > FAIL: gdb.cp/m-static.exp: static const int initialized nowhere (print field) > FAIL: gdb.cp/m-static.exp: ptype test4.nowhere > FAIL: gdb.cp/m-static.exp: print test4.nowhere.nowhere > FAIL: gdb.cp/m-static.exp: static const int initialized nowhere (whole > struct) > FAIL: gdb.cp/m-static.exp: static const int initialized in class definition > FAIL: gdb.cp/m-static.exp: static const float initialized in class definition > FAIL: gdb.cp/m-static.exp: info variable everywhere The "nowhere" failures are because this member is declared but not defined, and gdb expects it to be <optimized out>. So arguably a compiler perhaps but also just a weird test. I didn't look at the rest. I think the basic feature is probably fine and we're just seeing a difference between the test suite's expectations and what gcc has started doing in some corner cases.
Seems like Jakub thinks this is a gcc bug: https://gcc.gnu.org/pipermail/gcc-patches/2020-August/552502.html
(In reply to Tom Tromey from comment #2) > Seems like Jakub thinks this is a gcc bug: > https://gcc.gnu.org/pipermail/gcc-patches/2020-August/552502.html And his proposed gcc patch turns all the FAILs from description into PASSes (when building the gdb testsuite with -gdwarf-5 as default). So I'll close this bug.
Thank you for trying this out, it was very helpful.