]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
Handle DW_AT_encoding on DW_TAG_enumeration_type
authorTom Tromey <tromey@adacore.com>
Thu, 7 May 2026 18:08:40 +0000 (12:08 -0600)
committerTom Tromey <tromey@adacore.com>
Fri, 15 May 2026 20:27:09 +0000 (14:27 -0600)
commitebc3d2cc69d62103a08a4fbf90d36dfdd6743d9b
tree44d01d5f3a2b09e12437a3005f0fd105506fe684
parent5cb6772600a90b7a214b84277fc795c5d45e98fa
Handle DW_AT_encoding on DW_TAG_enumeration_type

A user pointed out a problem when printing certain values from an Ada
enumeration type.  Investigation showed that the problem was that some
enumeration constants were emitted using DW_FORM_data1, and were
incorrectly sign-extended by gdb.

First, this is yet another instance of a general problem with DWARF.
See https://sourceware.org/bugzilla/show_bug.cgi?id=32680 for the
analysis.

Meanwhile, it turns out that GCC implements an extension to handle
this scenario.  In particular, in non-strict mode, it will emit
DW_AT_encoding using either DW_ATE_signed or DW_ATE_unsigned.  This
was done back in 2017 by Pierre-Marie, in support of Ada -- but then
somehow nothing was ever implemented on the gdb side.  For this see
GCC commit f76f096e ("DWARF: add DW_AT_encoding attributes for
DW_TAG_enumeration_type DIEs").

This patch adds the missing code to gdb.  The included test case shows
the bug that was originally reported.  I've also included the snippet
from Pierre-Marie's commit message for good measure.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32680
Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb/dwarf2/read.c
gdb/testsuite/gdb.ada/enum-sign.exp [new file with mode: 0644]
gdb/testsuite/gdb.ada/enum-sign/prog.adb [new file with mode: 0644]