From patchwork Wed Sep 6 18:01:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 75390 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B2B2A385843E for ; Wed, 6 Sep 2023 18:01:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B2B2A385843E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1694023312; bh=YzsDbTzfYdHiZ/VcT7jhFeWRoYNVFI9tR1uu4SmraJs=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=C1YVtGAjY+4pLwWQ+ab/lIKW/neVkcKo9P0EcygPQr0goJCJrN4NLYsz5gyK7es7j St2hHYsIdw2725CLYtbDe5Glokcx/9FK0ovD70n6Xu3oLL0jLy9DTO8CZ9KPrDxwaS l2xV7GqWAo2aBLH3/wJIaCUL2e60murLpReVzVV8= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 9FA8F3858C78 for ; Wed, 6 Sep 2023 18:01:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9FA8F3858C78 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id C9A2C1F74C for ; Wed, 6 Sep 2023 18:01:26 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id B730B1333E for ; Wed, 6 Sep 2023 18:01:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id MzmAK3a++GTLLQAAMHmgww (envelope-from ) for ; Wed, 06 Sep 2023 18:01:26 +0000 To: gdb-patches@sourceware.org Subject: [PATCH] [gdb/ada] Move identical enums handling later Date: Wed, 6 Sep 2023 20:01:21 +0200 Message-Id: <20230906180121.31694-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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: , X-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" When running test-case gdb.ada/arr_acc_idx_w_gap.exp with target board cc-with-dwz, I run into: ... (gdb) print enum_with_gaps'enum_rep(lit3)^M 'Enum_Rep requires argument to have same type as enum^M (gdb) FAIL: gdb.ada/arr_acc_idx_w_gap.exp: enum_rep ... With target_board unix, we have instead: ... (gdb) print enum_with_gaps'enum_rep(lit3)^M $16 = 13^M (gdb) PASS: gdb.ada/arr_acc_idx_w_gap.exp: enum_rep ... Conversely, when I add this test to the test-case: ... gdb_test "print enum_with_gaps'enum_rep(lit3)" " = 13" \ "enum_rep" + gdb_test "print enum_subrange'enum_rep(lit3)" " = 13" \ + "other enum_rep" ... the extra test passes with target board cc-with-dwz, but fails with target board unix. The problem is here in remove_extra_symbols: ... if (symbols_are_identical_enums (syms)) syms.resize (1); ... where one of the two identical enums is picked before the enum_rep handling can resolve lit3 to one of the two. Fix this by moving the code to ada_resolve_variable. Tested on x86_64-linux. PR ada/30726 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30726 --- gdb/ada-lang.c | 35 ++++++++++++--------- gdb/testsuite/gdb.ada/arr_acc_idx_w_gap.exp | 2 ++ 2 files changed, 22 insertions(+), 15 deletions(-) base-commit: 313b2841b8e9046ea658104988e01bedf6148d5f diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index c0cc512bfa3..2e1b9664fdc 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -202,6 +202,8 @@ static struct type *ada_find_any_type (const char *name); static symbol_name_matcher_ftype *ada_get_symbol_name_matcher (const lookup_name_info &lookup_name); +static int symbols_are_identical_enums + (const std::vector &syms); /* The character set used for source files. */ @@ -3875,6 +3877,24 @@ ada_resolve_variable (struct symbol *sym, const struct block *block, && context_type->code () == TYPE_CODE_ENUM) i = ada_resolve_enum (candidates, sym->linkage_name (), context_type, parse_completion); + else if (context_type == nullptr + && symbols_are_identical_enums (candidates)) + { + /* If all the remaining symbols are identical enumerals, then + just keep the first one and discard the rest. + + Unlike what we did previously, we do not discard any entry + unless they are ALL identical. This is because the symbol + comparison is not a strict comparison, but rather a practical + comparison. If all symbols are considered identical, then + we can just go ahead and use the first one and discard the rest. + But if we cannot reduce the list to a single element, we have + to ask the user to disambiguate anyways. And if we have to + present a multiple-choice menu, it's less confusing if the list + isn't missing some choices that were identical and yet distinct. */ + candidates.resize (1); + i = 0; + } else if (deprocedure_p && !is_nonfunction (candidates)) { i = ada_resolve_function @@ -5091,21 +5111,6 @@ remove_extra_symbols (std::vector &syms) else i += 1; } - - /* If all the remaining symbols are identical enumerals, then - just keep the first one and discard the rest. - - Unlike what we did previously, we do not discard any entry - unless they are ALL identical. This is because the symbol - comparison is not a strict comparison, but rather a practical - comparison. If all symbols are considered identical, then - we can just go ahead and use the first one and discard the rest. - But if we cannot reduce the list to a single element, we have - to ask the user to disambiguate anyways. And if we have to - present a multiple-choice menu, it's less confusing if the list - isn't missing some choices that were identical and yet distinct. */ - if (symbols_are_identical_enums (syms)) - syms.resize (1); } /* Given a type that corresponds to a renaming entity, use the type name diff --git a/gdb/testsuite/gdb.ada/arr_acc_idx_w_gap.exp b/gdb/testsuite/gdb.ada/arr_acc_idx_w_gap.exp index 4a1482b6d99..a98e9e1e2c3 100644 --- a/gdb/testsuite/gdb.ada/arr_acc_idx_w_gap.exp +++ b/gdb/testsuite/gdb.ada/arr_acc_idx_w_gap.exp @@ -69,6 +69,8 @@ foreach_with_prefix scenario {all minimal} { gdb_test "print enum_with_gaps'enum_rep(lit3)" " = 13" \ "enum_rep" + gdb_test "print enum_subrange'enum_rep(lit3)" " = 13" \ + "other enum_rep" gdb_test "print enum_with_gaps'enum_val(21)" " = lit4" \ "enum_val" }