From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id SzuYAXWKBGqyZjYAWB0awg (envelope-from ) for ; Wed, 13 May 2026 10:28:05 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=e7nkPbkZ; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id E35711E093; Wed, 13 May 2026 10:28:04 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 9D7911E093 for ; Wed, 13 May 2026 10:28:03 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9261D4BA23D4 for ; Wed, 13 May 2026 14:28:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9261D4BA23D4 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=e7nkPbkZ Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by sourceware.org (Postfix) with ESMTPS id 155F94BB3B8D for ; Wed, 13 May 2026 14:27:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 155F94BB3B8D Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 155F94BB3B8D Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::230 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778682446; cv=none; b=ful765zBqVZYGjwEJnfmJAZot+WGZnvz64fUzzPZZRHKbABJWEHcPv2fewiFFkFoedCnfBfvE71WXQ61RQJid7kdKizXH1/46k/BbTLxctHRM8g7MPeomIa0shDRudajYQDafUKSpF9DKbVEI890Eg9Vu5+eEffkZ15wmFVLPR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778682446; c=relaxed/simple; bh=CnN7swMtvwZV1nAEVGYmLJqbooMyzrzz87XkVqE27J4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=QYPx1Jx86Evg7sPJZoggWFlMUIFpbS9slKtu0FCDhUSdtjfWY1q3zn2AVKH1kcjie/TEScFTOzbEwFYlQi6zHPKNke3iOxl5AnbbES8QTwl4uwky4xyf4P5vjzl5nOysZzMvsXCof77HcjMjHFap0+LTFULLNieyX4CZYsLLnDs= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=e7nkPbkZ DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 155F94BB3B8D Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-479e6bc357eso2681742b6e.2 for ; Wed, 13 May 2026 07:27:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1778682445; x=1779287245; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3ngHV8S8Z7a7KVsScULDT2C50TiL2PSQPbyeGkl+DlU=; b=e7nkPbkZm6hbGZf/C4685bCh8jYArj4eX2HuOA1EQ3z3ixK7tIOszBeQpmz2A2tOxx EXMSRz8lz45r868D4GE+3fa5pSMXjqt+o3iXrLowqtDRvph7Wdcs8weaYKFuy93IRVFi RMb+10duRJuUXyv/ToR05jJDtVk1CW7cuOfP+hsebLj0UomU5oOSACuQKxdktH5tsWxg 2kU4sJuuqOC0O4m9CTq/WCx420kGUkuK1j3HBkiziu6p0yadHyHVzLafSXujjzVl7wCF zP+A5ckBFzElyn8OUFGgRuGmNbSffXhgdbiMW9pNaH/R4rF1DSjW2ReE6wgSL6WS7r1D /hpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778682445; x=1779287245; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=3ngHV8S8Z7a7KVsScULDT2C50TiL2PSQPbyeGkl+DlU=; b=gVJoh+VpJ+Bnt6Qi4SrvAKaoSfsJ+Us+XJLoSrp6e+tB1UXYo+v8AoQm/i0LYbqQwV dQdgtsCOlftgbVV95g33OAI5SVGgNJ4OW26OJ+cyzIjwJnYTXBJUWysBmsoe375ZMZ4U jNtKCpKo8wSxwHoV5mVUceGMtlZyiMePGwkvJYrwb3sZNntd9Rv/gRkDL31Q3wGYOUG3 3GTT/6x8lkBUai+lXsOHFuRz7BVyawmj4sFZSG+gaXGHgTIvpeB1cS68QJEsrye0OMGA w0BsQsOTYX7kvcWdiIAgGFppCrF2ldhBcG+Sj+CzzxKq5DbRBn4MGd5bRGMrXyMvDT1A 27Gg== X-Gm-Message-State: AOJu0Yxo6ydJcN/neAHFpb6h/+uMOcq+7+bHvJSMLQlRPWTPhq4XSfPO 51T9qNeeyKHpirsNhPQpT6LjWWYrV1uTNc27NmklkD3Qhw6/gducdnimxH9M2y86BU2niduwUo6 NuW8= X-Gm-Gg: Acq92OEvMAgmLAaQqUcyrRkQDlHNJ/3kn3SNP9JpkVDc0M0BaxqK+dPX7gwQgJm/6uv WVEGmrIsKOUGSj6JIHMBk2h3+MR/sdsheRRQnzL8S+J2JHZ26VsI96gp/F/sktF5ttS4/URVZ2P Uc9AfytigN9OJDBC4RiHkqlhwHXKIcdAAbNgA9qhLV/fMx3zLkHPiwwUSWNoH9heormI1fmYVGs kPuwsZY7GszpFWNQXC347yuTShxNx/4n3hOHlS211zmMvkg0fzUjawLEBmkdvZgPQE3EhAAy9zs VLGNflQd7uG36FqJK/10lg3EcXL8qKExb/wVzE4w/RqUYJduVwVWAeopGIyqdUhAw4zi4MXB+qO n0fgl1E8aidVVgKYZ+2WG1ViArDf6LN3IZ2OBRJFKwmbr2COUO886Pwpvs6ttSWbTgLxV3rWzMN b+Xd88+g8KK8nI8IyIWkn5v+5mzJYrskoXR6cRsOFXCoQ= X-Received: by 2002:a05:6808:168a:b0:482:720f:feba with SMTP id 5614622812f47-482b2cf248fmr2083161b6e.22.1778682445105; Wed, 13 May 2026 07:27:25 -0700 (PDT) Received: from bapiya (75-166-225-82.hlrn.qwest.net. [75.166.225.82]) by smtp.gmail.com with ESMTPSA id 5614622812f47-47c76986404sm24410233b6e.15.2026.05.13.07.27.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2026 07:27:24 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Handle DW_AT_encoding on DW_TAG_enumeration_type Date: Wed, 13 May 2026 08:27:22 -0600 Message-ID: <20260513142722.3135998-1-tromey@adacore.com> X-Mailer: git-send-email 2.54.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org 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. --- gdb/dwarf2/read.c | 16 ++ gdb/testsuite/gdb.ada/enum-sign.exp | 40 +++ gdb/testsuite/gdb.ada/enum-sign/prog.adb | 331 +++++++++++++++++++++++ 3 files changed, 387 insertions(+) create mode 100644 gdb/testsuite/gdb.ada/enum-sign.exp create mode 100644 gdb/testsuite/gdb.ada/enum-sign/prog.adb diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index efe96f6510d..de5690202b2 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -11171,6 +11171,22 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) set_type_align (type, TYPE_RAW_ALIGN (underlying_type)); } + /* DW_AT_encoding on an enumeration type is a GCC extension. GCC + will only emit DW_ATE_signed or DW_ATE_unsigned here. If this is + seen, it provides a way to find the signed-ness without having to + guess based on the constants, which is somewhat fraught anyway + (see PR symtab/32680). */ + if (!is_unsigned.has_value ()) + { + attribute *encoding_attr = dwarf2_attr (die, DW_AT_encoding, cu); + if (encoding_attr != nullptr) + { + std::optional val = encoding_attr->unsigned_constant (); + if (val.has_value ()) + is_unsigned = *val == DW_ATE_unsigned; + } + } + type->set_is_declared_class (dwarf2_flag_true_p (die, DW_AT_enum_class, cu)); type->set_endianity_is_not_default (die_byte_order (die, cu, nullptr)); diff --git a/gdb/testsuite/gdb.ada/enum-sign.exp b/gdb/testsuite/gdb.ada/enum-sign.exp new file mode 100644 index 00000000000..84098027849 --- /dev/null +++ b/gdb/testsuite/gdb.ada/enum-sign.exp @@ -0,0 +1,40 @@ +# Copyright 2026 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +load_lib "ada.exp" + +require allow_ada_tests + +standard_ada_testfile prog + +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable debug] != ""} { + return +} + +clean_restart ${testfile} + +set bp_location [gdb_get_line_number "STOP" ${testdir}/prog.adb] +runto "prog.adb:$bp_location" + +for {set num 0} {$num <= 300} {incr num} { + gdb_test "print Value_$num" " = value_$num" + gdb_test "print Unsigned_Enumeration'Val($num)" " = value_$num" + gdb_test "print/d Unsigned_Enumeration'Val($num)" " = $num" +} + +foreach {name dec} {se_a -1 se_b 0 se_c 1 se_d 2} { + gdb_test "print $name" " = $name" + gdb_test "print/d $name" " = $dec" +} diff --git a/gdb/testsuite/gdb.ada/enum-sign/prog.adb b/gdb/testsuite/gdb.ada/enum-sign/prog.adb new file mode 100644 index 00000000000..6ef3c956917 --- /dev/null +++ b/gdb/testsuite/gdb.ada/enum-sign/prog.adb @@ -0,0 +1,331 @@ +-- Copyright 2026 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +procedure Prog is + type Unsigned_Enumeration is + ( + Value_0, + Value_1, + Value_2, + Value_3, + Value_4, + Value_5, + Value_6, + Value_7, + Value_8, + Value_9, + Value_10, + Value_11, + Value_12, + Value_13, + Value_14, + Value_15, + Value_16, + Value_17, + Value_18, + Value_19, + Value_20, + Value_21, + Value_22, + Value_23, + Value_24, + Value_25, + Value_26, + Value_27, + Value_28, + Value_29, + Value_30, + Value_31, + Value_32, + Value_33, + Value_34, + Value_35, + Value_36, + Value_37, + Value_38, + Value_39, + Value_40, + Value_41, + Value_42, + Value_43, + Value_44, + Value_45, + Value_46, + Value_47, + Value_48, + Value_49, + Value_50, + Value_51, + Value_52, + Value_53, + Value_54, + Value_55, + Value_56, + Value_57, + Value_58, + Value_59, + Value_60, + Value_61, + Value_62, + Value_63, + Value_64, + Value_65, + Value_66, + Value_67, + Value_68, + Value_69, + Value_70, + Value_71, + Value_72, + Value_73, + Value_74, + Value_75, + Value_76, + Value_77, + Value_78, + Value_79, + Value_80, + Value_81, + Value_82, + Value_83, + Value_84, + Value_85, + Value_86, + Value_87, + Value_88, + Value_89, + Value_90, + Value_91, + Value_92, + Value_93, + Value_94, + Value_95, + Value_96, + Value_97, + Value_98, + Value_99, + Value_100, + Value_101, + Value_102, + Value_103, + Value_104, + Value_105, + Value_106, + Value_107, + Value_108, + Value_109, + Value_110, + Value_111, + Value_112, + Value_113, + Value_114, + Value_115, + Value_116, + Value_117, + Value_118, + Value_119, + Value_120, + Value_121, + Value_122, + Value_123, + Value_124, + Value_125, + Value_126, + Value_127, + Value_128, + Value_129, + Value_130, + Value_131, + Value_132, + Value_133, + Value_134, + Value_135, + Value_136, + Value_137, + Value_138, + Value_139, + Value_140, + Value_141, + Value_142, + Value_143, + Value_144, + Value_145, + Value_146, + Value_147, + Value_148, + Value_149, + Value_150, + Value_151, + Value_152, + Value_153, + Value_154, + Value_155, + Value_156, + Value_157, + Value_158, + Value_159, + Value_160, + Value_161, + Value_162, + Value_163, + Value_164, + Value_165, + Value_166, + Value_167, + Value_168, + Value_169, + Value_170, + Value_171, + Value_172, + Value_173, + Value_174, + Value_175, + Value_176, + Value_177, + Value_178, + Value_179, + Value_180, + Value_181, + Value_182, + Value_183, + Value_184, + Value_185, + Value_186, + Value_187, + Value_188, + Value_189, + Value_190, + Value_191, + Value_192, + Value_193, + Value_194, + Value_195, + Value_196, + Value_197, + Value_198, + Value_199, + Value_200, + Value_201, + Value_202, + Value_203, + Value_204, + Value_205, + Value_206, + Value_207, + Value_208, + Value_209, + Value_210, + Value_211, + Value_212, + Value_213, + Value_214, + Value_215, + Value_216, + Value_217, + Value_218, + Value_219, + Value_220, + Value_221, + Value_222, + Value_223, + Value_224, + Value_225, + Value_226, + Value_227, + Value_228, + Value_229, + Value_230, + Value_231, + Value_232, + Value_233, + Value_234, + Value_235, + Value_236, + Value_237, + Value_238, + Value_239, + Value_240, + Value_241, + Value_242, + Value_243, + Value_244, + Value_245, + Value_246, + Value_247, + Value_248, + Value_249, + Value_250, + Value_251, + Value_252, + Value_253, + Value_254, + Value_255, + Value_256, + Value_257, + Value_258, + Value_259, + Value_260, + Value_261, + Value_262, + Value_263, + Value_264, + Value_265, + Value_266, + Value_267, + Value_268, + Value_269, + Value_270, + Value_271, + Value_272, + Value_273, + Value_274, + Value_275, + Value_276, + Value_277, + Value_278, + Value_279, + Value_280, + Value_281, + Value_282, + Value_283, + Value_284, + Value_285, + Value_286, + Value_287, + Value_288, + Value_289, + Value_290, + Value_291, + Value_292, + Value_293, + Value_294, + Value_295, + Value_296, + Value_297, + Value_298, + Value_299, + Value_300 + ); + + X : Unsigned_Enumeration := Value_23; + + type Signed_Enumeration is ( SE_A, SE_B, SE_C, SE_D); + for Signed_Enumeration use (-1, 0, 1, 2); + + Y : Signed_Enumeration := SE_D; + +begin + null; -- STOP +end; base-commit: 2d7f2dbbd4adadf7c388fa0d8b9ce95d9dfde641 -- 2.54.0