Bug 16063 - Debuggers need more information about enum types in C++
Summary: Debuggers need more information about enum types in C++
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: 3.4.0
: P2 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 54774 (view as bug list)
Depends on:
Blocks: 63243
  Show dependency treegraph
 
Reported: 2004-06-18 16:12 UTC by jcownie
Modified: 2014-09-12 13:44 UTC (History)
3 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 4.0.0
Known to fail:
Last reconfirmed: 2006-01-29 17:57:23


Attachments
Test case with embedded description. (738 bytes, text/plain)
2004-06-18 16:14 UTC, jcownie
Details
Patch against 3.4.0 (274 bytes, patch)
2004-06-18 16:27 UTC, jcownie
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description jcownie 2004-06-18 16:12:55 UTC
The debug information emitted for enumerated types does not allow a debugger
to unambiguously determine the "underlying type" of the enumeration.

A debugger therefore does not have enough information to allow it to perform
overload resolution when asked to evaluate a function call with an enum type
as an actual argument.

One can view this either as a bug (the compiler is emitting an unsigned value
using DW_FORM_sdata), or as requiring an enhancement.

I believe the simplest solution would be to have the compiler be explicit about 
the representation of the enum type by emitting a DW_AT_encoding with the
DW_TAG_enumeration, so that the debugger is explicitly told whether the 
underlying type of the enumeration is signed or unsigned.

See the (about to be attached) test case for detailed information.
Comment 1 jcownie 2004-06-18 16:14:46 UTC
Created attachment 6565 [details]
Test case with embedded description.
Comment 2 Andrew Pinski 2004-06-18 16:22:52 UTC
Confirmed, I should note that ICC 6.0 does not do this also.
Comment 3 jcownie 2004-06-18 16:27:08 UTC
Created attachment 6566 [details]
Patch against 3.4.0

This simple patch does everything we need, I believe.
Comment 4 jcownie 2004-06-18 16:31:13 UTC
Subject: Re:  Debuggers need more information about enum types in C++ 


> Confirmed, I should note that ICC 6.0 does not do this also.

Right, it's an extension to the DWARF standard to require this. 

I have submitted changes to add this to DWARF to the DWARF2 maliing
lists, but have yet to receive feedback.

I have also submitted it as a bug report to Intel against their latest
compiler ;-)

I imagine their fix may take longer than yours if you're happy with
the (one line of code) patch which I just submitted.

Comment 5 Tom Tromey 2012-06-29 13:50:49 UTC
DWARF 4 allows this:

The enumeration type entry may have a DW_AT_type attribute which refers to the underlying
data type used to implement the enumeration.

I think this is definitely needed for "enum class", where the base
type can be specified by the user.
However, emitting it unconditionally wouldn't hurt.
Comment 6 Mark Wielaard 2014-03-23 11:22:24 UTC
Posted a patch:
http://gcc.gnu.org/ml/gcc-patches/2014-03/msg01198.html
Comment 7 Mark Wielaard 2014-05-21 15:45:31 UTC
Author: mark
Date: Wed May 21 15:44:59 2014
New Revision: 210717

URL: http://gcc.gnu.org/viewcvs?rev=210717&root=gcc&view=rev
Log:
PR debug/16063. Add DW_AT_type to DW_TAG_enumeration.

Add a new lang-hook that provides the underlying base type of an
ENUMERAL_TYPE. The default implementation will just use type_for_size.
The implementation for C++ will use the ENUM_UNDERLYING_TYPE if it exists.
Use this enum_underlying_base_type lang-hook in dwarf2out.c to add a
DW_AT_type base type reference to a DW_TAG_enumeration.

gcc/
	* dwarf2out.c (gen_enumeration_type_die): Add DW_AT_type if DWARF
	version >= 3 or not strict DWARF.
	* langhooks.h (struct lang_hooks_for_types): Add
	enum_underlying_base_type.
	* langhooks.c (lhd_enum_underlying_base_type): New function.
	* gcc/langhooks.h (struct lang_hooks_for_types): Add
	enum_underlying_base_type.
	* langhooks-def.h (lhd_enum_underlying_base_type): New declaration.
	(LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): New define.
	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Add new lang hook.

gcc/cp/
	* cp-lang.c (cxx_enum_underlying_base_type): New function.
	(LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE): Define.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-lang.c
    trunk/gcc/dwarf2out.c
    trunk/gcc/langhooks-def.h
    trunk/gcc/langhooks.c
    trunk/gcc/langhooks.h
Comment 8 Tom Tromey 2014-06-25 18:55:30 UTC
*** Bug 54774 has been marked as a duplicate of this bug. ***
Comment 9 Marek Polacek 2014-09-12 11:40:38 UTC
So, is this fixed?
Comment 10 Mark Wielaard 2014-09-12 11:53:20 UTC
(In reply to Marek Polacek from comment #9)
> So, is this fixed?

Yes, I do believe so, in gcc trunk. Sorry for not closing earlier.