From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 2P5nJbk3RWrqUyEAWB0awg (envelope-from ) for ; Wed, 01 Jul 2026 11:52:25 -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=OynV0eOf; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 7B6361E024; Wed, 01 Jul 2026 11:52:25 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.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 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 BF6821E024 for ; Wed, 01 Jul 2026 11:52:24 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7AD1D4BA2E30 for ; Wed, 1 Jul 2026 15:52:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7AD1D4BA2E30 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=OynV0eOf Received: from mail-oo1-xc2c.google.com (mail-oo1-xc2c.google.com [IPv6:2607:f8b0:4864:20::c2c]) by sourceware.org (Postfix) with ESMTPS id 9448C4BA543C for ; Wed, 1 Jul 2026 15:51:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9448C4BA543C 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 9448C4BA543C Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c2c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782921118; cv=none; b=YEw+NG4Fa0vYhGzd7mqKMNRiZYyx1W7yRC7YU5NVbdBBmf9nrqQu3PlGtdo8rkHoV1ByRoHlV6g+YEfBLOik4YBbT8Qag3PelFTe+mm0DqRSFMDKNB20JwTbvEKFSYdv2Y8GiWYjAIjcbpD7crKMmDZEUwiOIE+F+BTHlgRMZic= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782921118; c=relaxed/simple; bh=uKWIneWT8IdZUQ9QPJmFz2rP2AI4we8RQXIEiM2iE9o=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Kls57sIXp9FJlAKhMF+lEeeqzIhyQaGBldudVpsQIKaqsPSuDDpjhf64W0fELoaDvybdjmROgpvqIQQAdrPSbuWfMxkYr9WnSIFpgB9V1fxFjtPaSE86NAC+plta0O/WZdeG3nNhA4UbgdRV1SUxkklAVSNrwKyTF18YrfzPXAo= 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=OynV0eOf DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9448C4BA543C Received: by mail-oo1-xc2c.google.com with SMTP id 006d021491bc7-6a0c7c4f55fso547240eaf.2 for ; Wed, 01 Jul 2026 08:51:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1782921118; x=1783525918; 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=oOuWME6IhXpCbgEsf6M5cIT8kcFE+8GJr/1fL0HTDgs=; b=OynV0eOfyF0VE6/3EiszT/FUjTUL9LN4rH/Tm1LKAX290hRqe+6+ZDFnNe09y36j/l v/Trz9SPHgpH7M7GtAJZoNkGmLAXJP6O3lPPDPz2ca4mHm9E2+rg/73SUAL+8CEfMz1M YJtfjG8t+we4E2lD79UVGYrFiw27isq/aDdXbwMpDMkNAM5MRwj2lhK98snNmM9uOnp5 I0HO8VfBYG2vJgCJmxVWtBTgGrbeAnYUwMrRe5839bFBT0tilzVbu6Zyq4rvPzUTfYmI x2krZ7SC30WPJtnnTY7mqPlSvyrRON30YVzMCopMxVGs3wjVMHEs6ktCrTonRjXXEYl5 s1yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782921118; x=1783525918; 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=oOuWME6IhXpCbgEsf6M5cIT8kcFE+8GJr/1fL0HTDgs=; b=hLkLCeSTC5qP4BUyvFPIy/W+1xQvaP3I67Q4FX2wtlh0AdDNs6choez3FeICjBErIh v7uJeEVit6Coq+2pV/mCtC+pbwCkdWptynolrgqsQhGmcf7ITFsAhRhQUmDCHxsgJVoW rEcGGtKXxe+AEQYb71oN0PjxrQ0zs6HU9zN9qUhPCwISlsb9kBnK9cZMMsIrFfmy2USD k56de4TkuhePTeMG9Vk0Q+fTPq6cAmMboiKkV1Rl+Eh0xMMqVzHwuo0u9WzunhJRiZ8w xo/BNzGxQE8Cc/duM6n1ezoJu91Hr565UE6aqopCg2MsEBginq9KKZuDMDoe60GacOlp T7Aw== X-Gm-Message-State: AOJu0YzMMLdibatZBMzp0C4WKj+QJeOmf5aFhoXfoxFTPLiHk5sq2/pF tCe4J6geBfug5iSUjFm7KJXUf9Tgq3S2Gs1Ni8v5Pv34nlNYNHQtTnbPxoZwN8TobH8IqW7+1aS bK+s= X-Gm-Gg: AfdE7cn2i3q97T8n2IbkMvzr3YMArs4KfYHx6WW36XUqSFhsJLrXFMjvUAI1qGS0tuc 1ivIkkQyPPzrCgPFiZbJJNB6ZXow0B9GydzLBZ6gz116byl6QeVxDLtZKzfjp9/N9eMd7Xky6wc oJvRlOZVc1o/lRWpJY3eQF0givVOMZ5nv5Dk2xwPNXPDa7E3ug+5KQ8haa/rHwoF4cr9+7BbVvy Jh92cmRqe7jR7GkiIFb7NfSbwQd6TWSmgNYWlu1aTXBcgdh5Pkq5z22XJArzNAhJePPdQS7CFBy KG+OjZ8TGr2vqhoycZRNzria1JvNgm2s5J9e8Qmv4RBNvsGbs83u64tV+81gF0yRR7mafVx+XAM QS5DK+xDS7ND05VOv8GTYz3Yw94diGTOIU4sxwiIXiYYkvg2NwbalBI3QVpjVupyl7mjqx42IFv gebzgMB+VobAhY77RN3L4lzK4q0jWNDWyO X-Received: by 2002:a05:6820:1512:b0:6a1:50eb:2110 with SMTP id 006d021491bc7-6a309b831e1mr1174239eaf.69.1782921117830; Wed, 01 Jul 2026 08:51:57 -0700 (PDT) Received: from bapiya (75-166-225-82.hlrn.qwest.net. [75.166.225.82]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-44cbe8d9c13sm72157fac.7.2026.07.01.08.51.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2026 08:51:57 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Handle missing array descriptor in ada_type_of_array Date: Wed, 1 Jul 2026 09:51:55 -0600 Message-ID: <20260701155155.1958074-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 The test case gdb.ada/mi_var_access.exp was failing with gnat-llvm. Debugging this, I found that the problem was that with gnat-llvm, the array descriptor would have a NULL pointer for the bounds when the array was invalidated. That is, examining the object in C mode: (gdb) p a_string_access $1 = { P_ARRAY = 0x0, P_BOUNDS = 0x0 } whereas when using GNAT we see: (gdb) print a_string_access $1 = { P_ARRAY = 0x0, P_BOUNDS = 0x402750 } This was causing ada_type_of_array to return nullptr; with that bubbling up to varobj and then MI as a "wrong" type in the MI output. It seems to me that a null P_BOUNDS is reasonable; and that this case can be handled in ada_type_of_array by examining the type of P_BOUNDS without needing the bounds themselves. The bound values are both set to 0 in this case, because experimentally this is what is done at runtime in the GNAT-generated code. Perhaps an explicitly empty array (1/0) would be better; I am not certain. --- gdb/ada-lang.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 35ebd924021..85166c646bf 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -2177,20 +2177,35 @@ ada_type_of_array (struct value *arr, int bounds) descriptor = desc_bounds (arr); /* In the extended access case, the bounds struct is "inline" so the pointer cannot be NULL. */ - if (ada_check_typedef (descriptor->type ())->code () == TYPE_CODE_PTR - && value_as_long (descriptor) == 0) - return NULL; + const bool has_descriptor + = (ada_check_typedef (descriptor->type ())->code () != TYPE_CODE_PTR + || value_as_long (descriptor) != 0); while (arity > 0) { type_allocator alloc (arr->type ()); - struct value *low = desc_one_bound (descriptor, arity, 0); - struct value *high = desc_one_bound (descriptor, arity, 1); + LONGEST low = 0, high = 0; + type *bound_type; + + if (has_descriptor) + { + struct value *low_v = desc_one_bound (descriptor, arity, 0); + struct value *high_v = desc_one_bound (descriptor, arity, 1); + low = value_as_long (low_v); + high = value_as_long (high_v); + bound_type = low_v->type (); + } + else + { + /* We don't have the bounds, but we can still find the + type of each index. */ + bound_type + = desc_index_type (descriptor->type ()->target_type (), + arity); + } arity -= 1; struct type *range_type - = create_static_range_type (alloc, low->type (), - value_as_long (low), - value_as_long (high)); + = create_static_range_type (alloc, bound_type, low, high); elt_type = create_array_type (alloc, elt_type, range_type); INIT_GNAT_SPECIFIC (elt_type); @@ -2199,18 +2214,15 @@ ada_type_of_array (struct value *arr, int bounds) /* We need to store the element packed bitsize, as well as recompute the array size, because it was previously computed based on the unpacked element size. */ - LONGEST lo = value_as_long (low); - LONGEST hi = value_as_long (high); - elt_type->field (0).set_bitsize (decode_packed_array_bitsize (arr->type ())); /* If the array has no element, then the size is already zero, and does not need to be recomputed. */ - if (lo < hi) + if (low < high) { - int array_bitsize = - (hi - lo + 1) * elt_type->field (0).bitsize (); + int array_bitsize = ((high - low + 1) + * elt_type->field (0).bitsize ()); elt_type->set_length ((array_bitsize + 7) / 8); } base-commit: 54e80f9747d62efea50038655801ecb58d37b507 -- 2.54.0