Bug 58150 - debug info about definition of enum class not emitted if the declaration was already used in a class
Summary: debug info about definition of enum class not emitted if the declaration was ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: 4.8.1
: P3 normal
Target Milestone: ---
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-14 00:08 UTC by Ben Longbons
Modified: 2018-06-21 19:39 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-10-17 00:00:00


Attachments
minimal testcase (143 bytes, text/x-c++src)
2013-08-14 00:08 UTC, Ben Longbons
Details
another testcase (338 bytes, text/x-csrc)
2017-10-16 21:54 UTC, npl
Details
gcc8-pr58150.patch (1.58 KB, patch)
2018-03-09 14:24 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ben Longbons 2013-08-14 00:08:53 UTC
Created attachment 30649 [details]
minimal testcase

If an enum class has a forward declaration and it is used as a class member (functions seem to be okay), the full debuginfo is not emitted when the definition appear later in the TU.

This makes debugging practically impossible.

enums are unusual in that they can be fully used even when they have just a definition.

Tested gcc versions:
g++-4.6 (Debian 4.6.4-2) 4.6.4
g++-4.7 (Debian 4.7.3-4) 4.7.3
g++-4.8 (Debian 4.8.1-8) 4.8.1

Versions before 4.6 did not implement forward declarations of enum classes, so this bug is primordial.

The relevant part of the debug information looks like:

 <1><34>: Abbrev Number: 3 (DW_TAG_enumeration_type)
    <35>   DW_AT_name        : (indirect string, offset: 0x84): ByteCode
    <39>   DW_AT_enum_class  : 1
    <39>   DW_AT_declaration : 1
    <39>   DW_AT_byte_size   : 1
    <3a>   DW_AT_decl_file   : 1
    <3b>   DW_AT_decl_line   : 3

Whereas clang generates:

 <1><6f>: Abbrev Number: 6 (DW_TAG_enumeration_type)
    <70>   DW_AT_type        : <0x64>
    <74>   DW_AT_enum_class  : 1
    <75>   DW_AT_name        : (indirect string, offset: 0x98): ByteCode
    <79>   DW_AT_byte_size   : 1
    <7a>   DW_AT_decl_file   : 1
    <7b>   DW_AT_decl_line   : 10
Comment 1 Ben Longbons 2014-03-28 17:11:37 UTC
Still present in gcc 4.9 as of 2014-03-22

Currently I'm hacking around this by using a gdb pretty printer that hard-codes the enum values and turns them into strings, but that only works for printing, not calls.
Comment 2 npl 2017-10-16 21:54:59 UTC
Created attachment 42381 [details]
another testcase

I was generating a testcase before discovering this bug.
Problem is the same:

A class/struct using a prototyped, not yet defined "enum class" will prevent that debug information for this "enum class" to be emitted.
Only if no class/struct uses a "enum class" before its defined, the debug info will be available.

Affected: GCC 5.3.0, GCC 6.4.0, GCC 7.2.0

Please fix this, it really makes debugging a pain
Comment 3 Eric Gallager 2017-10-17 20:31:34 UTC
(In reply to npl from comment #2)
> Created attachment 42381 [details]
> another testcase
> 
> I was generating a testcase before discovering this bug.
> Problem is the same:
> 
> A class/struct using a prototyped, not yet defined "enum class" will prevent
> that debug information for this "enum class" to be emitted.
> Only if no class/struct uses a "enum class" before its defined, the debug
> info will be available.
> 
> Affected: GCC 5.3.0, GCC 6.4.0, GCC 7.2.0
> 
> Please fix this, it really makes debugging a pain

Taking this as confirmation.
Comment 4 Jakub Jelinek 2018-03-09 14:24:40 UTC
Created attachment 43606 [details]
gcc8-pr58150.patch

Untested fix.
Comment 5 Jakub Jelinek 2018-03-11 16:50:40 UTC
Author: jakub
Date: Sun Mar 11 16:50:08 2018
New Revision: 258434

URL: https://gcc.gnu.org/viewcvs?rev=258434&root=gcc&view=rev
Log:
	PR debug/58150
	* dwarf2out.c (gen_enumeration_type_die): Don't guard adding
	DW_AT_declaration for ENUM_IS_OPAQUE on -gdwarf-4 or -gno-strict-dwarf,
	but on TYPE_SIZE.  Don't do anything for ENUM_IS_OPAQUE if not creating
	a new die.  Don't set TREE_ASM_WRITTEN if ENUM_IS_OPAQUE.  Guard
	addition of most attributes on !orig_type_die or the attribute not
	being present already.  Assert TYPE_VALUES is NULL for ENUM_IS_OPAQUE.

	* g++.dg/debug/dwarf2/enum2.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/debug/dwarf2/enum2.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/dwarf2out.c
    trunk/gcc/testsuite/ChangeLog
Comment 6 Jakub Jelinek 2018-03-11 17:03:42 UTC
Fixed for 8.1+.
Comment 7 Jakub Jelinek 2018-06-21 19:39:34 UTC
.