From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 0BCC83858C2D for ; Thu, 7 Sep 2023 14:42:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0BCC83858C2D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de 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 A88F41F88E for ; Thu, 7 Sep 2023 14:42:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1694097756; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=yhZuknQlLymlerQyItXR+mjB4rQb734MRYN4Ocuphuw=; b=uPh5CsNd/l6/bO4x4AhN65v+gWfnR8gX01A0Ux/k8+G6z5oeOgJVQeiA0TBDD6z/Q1FuB8 MIyUMvf7BgliG9+z+o5M9o97pUFlqhQIKir8ROC0DzU+7AMh1B74GLm5hHKw1nOIT5zD5v K5UcqJarf/q3obKBf5RMTJx3KRyjEC0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1694097756; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=yhZuknQlLymlerQyItXR+mjB4rQb734MRYN4Ocuphuw=; b=+ndTxhxoNbrm+9cgri21/Kca+KiFW5yAgVWpDB/A/lpsVFdlcMSu4Ev+lIiKnk467tJSjp fhv5HZXvuvyqyZAA== 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 974B6138F9 for ; Thu, 7 Sep 2023 14:42:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +X3II1zh+WSRZAAAMHmgww (envelope-from ) for ; Thu, 07 Sep 2023 14:42:36 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH] [gdb/ada] Extend type equivalence test in ada_resolve_enum Date: Thu, 7 Sep 2023 16:42:32 +0200 Message-Id: <20230907144233.14505-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 List-Id: When running test-case gdb.ada/local-enum.exp with target board debug-types, I run into: ... (gdb) print v1(three)^M No name 'three' in enumeration type 'local__e1'^M (gdb) FAIL: gdb.ada/local-enum.exp: print v1 element ... The array V1 is of type A1 which is an array with index type E1, containing "three" as enumerator: ... type E1 is (one, two, three); type A1 is array (E1) of Integer; V1 : A1 := (0, 1, 2); ... There's also a type E2 that contains three as enumerator: ... type E2 is (three, four, five); ... When doing "print v1(three)", it's the job of ada_resolve_enum to resolve "three" to type E1 rather than type E2. When using target board debug-types, the enums E1 and E2 are replicated in the .debug_types section, and consequently in ada_resolve_enum the type equivalence check using a pointer comparison fails: ... for (int i = 0; i < syms.size (); ++i) { /* We already know the name matches, so we're just looking for an element of the correct enum type. */ if (ada_check_typedef (syms[i].symbol->type ()) == context_type) return i; } ... Fix this by also trying a structural comparison using ada_identical_enum_types_p. Tested on x86_64-linux. PR ada/29335 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29335 --- gdb/ada-lang.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index c0cc512bfa3..7b61cce9341 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -202,6 +202,7 @@ 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 ada_identical_enum_types_p (struct type *type1, struct type *type2); /* The character set used for source files. */ @@ -3799,11 +3800,24 @@ ada_resolve_enum (std::vector &syms, gdb_assert (context_type->code () == TYPE_CODE_ENUM); context_type = ada_check_typedef (context_type); + /* We already know the name matches, so we're just looking for + an element of the correct enum type. */ + struct type *type1 = context_type; for (int i = 0; i < syms.size (); ++i) { - /* We already know the name matches, so we're just looking for - an element of the correct enum type. */ - if (ada_check_typedef (syms[i].symbol->type ()) == context_type) + struct type *type2 = ada_check_typedef (syms[i].symbol->type ()); + if (type1 == type2) + return i; + } + + for (int i = 0; i < syms.size (); ++i) + { + struct type *type2 = ada_check_typedef (syms[i].symbol->type ()); + if (type1->num_fields () != type2->num_fields ()) + continue; + if (strcmp (type1->name (), type2->name ()) != 0) + continue; + if (ada_identical_enum_types_p (type1, type2)) return i; } base-commit: 4d944db22c351296bad0b54d6a1857ad1fbde575 -- 2.35.3