From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id sRpMLYsb0GnQBwYAWB0awg (envelope-from ) for ; Fri, 03 Apr 2026 15:56:59 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bTnJ7P8A; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id A9EF31E04F; Fri, 03 Apr 2026 15:56:59 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,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 D07821E04F for ; Fri, 03 Apr 2026 15:56:58 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 84CF04BA23DB for ; Fri, 3 Apr 2026 19:56:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 84CF04BA23DB Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bTnJ7P8A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id AFCA84BA2E36 for ; Fri, 3 Apr 2026 19:56:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AFCA84BA2E36 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AFCA84BA2E36 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775246187; cv=none; b=cfKu69BB389ByvXcKnHd06HqHDt+94E2RtVxYkQpniAgP//C8I1mOWhPxDUwxwO7npmUL16kIzw8JDw7S7Fcyks7ExomlqY0WtN0QjeWgKMsdiMXkuXtxxvw96VBBPPOeqZFj61TeOPC7Y8xQG9Pphc1Z0mOwXV59l7Jeg+X5dc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775246187; c=relaxed/simple; bh=RSEHPcIaYfUJfW49ubx0/PDjpA51KYqnYqzyjMOFs08=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=IbEBZ12jRjP4SOhyJEG01aaKnfu0gp4cVNpIdhtO/NvlpuAGPUj807q21ikgQ1eN30ui9c9dqJFUeGcZp6CC/X44x6wtXkzeM3HCZji6CQGh1DDYrVyKzqXH1i7wfrcMmQUwLlRbXIT+vfKav6xIFc36krzUChRXwUOuFDgACDU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AFCA84BA2E36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775246187; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X8t9giXJQM5TDtYm5DqVaJMNZH2YEUSj43OcJK3ponE=; b=bTnJ7P8Agtd7AB2qaqow4dI5USVapnz2ENyOi9W0PVPa/+Y2d+8vVluX20cPKrWvw16H5a vuMZLA1wuPZ0z8cIjKfyuYnzKzvUED61owsyNfmu9Mb3dZYyZIhCuTb4vfx1rmgYzuwB82 XRH9gZr/Z7edpjjFjbRKTf0/hfk2dqY= Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-547-heaAeqT6PzmxGFbbXh9Kvg-1; Fri, 03 Apr 2026 15:56:25 -0400 X-MC-Unique: heaAeqT6PzmxGFbbXh9Kvg-1 X-Mimecast-MFC-AGG-ID: heaAeqT6PzmxGFbbXh9Kvg_1775246185 Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-2b0f4e632caso31210965ad.3 for ; Fri, 03 Apr 2026 12:56:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775246184; x=1775850984; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=X8t9giXJQM5TDtYm5DqVaJMNZH2YEUSj43OcJK3ponE=; b=m/Rpq8tvX2bAzbdRDaEG2eicjE/pwXk8yiAWdjviOtwJ5ww9H1cP73Nb70ocN9YW9p i1LCVcZKAjG309pfSxnmI9cpeXdbXyU6hfcEC9m23IX+bGHxv7ZsKFeAmXpSsS1Bu0jh vBtKRFtysIFnwAUyyYdlMJAeSel7HndCo3Iu+6k0LaWQZejiWY1TKd3JkS6kZDtQvutG kSKlTHRA6uo37xWR5boAxZvN/nro5Nbzun/yJlL5GMANzbnzDTYsQNestQjcTLY0x9e1 pWbArlXQthQ6IQoiNzXjDejm4jd7CP6QcKsd826UIEH+m6zbBsKQsj1Fnqcx8G/3hxky EnGg== X-Forwarded-Encrypted: i=1; AJvYcCWfDZK5xE8x2MZvb5wbtRTvVt40Ng5Bc8cTDTdarq1+i1WnO4ZrvK29L+6V/2wtHJVkxX1glT5WRFeaFg==@sourceware.org X-Gm-Message-State: AOJu0YwTluB2tdJnqHRnbPNiOcugtUitg8NbhI2RhiB6ltN85dBiBt2K c6NHYgH/Pi7nqQlfDKyL9EjLi5SX5J74QmeFU7cxzstip1aknrA6zwUQiZe0AqkKsZ9jArKhdVY +XH24lMnbQPl+qm+rErAJz8YgwFX0rAakj2aZZ8OeZx5Dz/ydAeA0eVhXFFFpL6pXMzR9ma0= X-Gm-Gg: AeBDievWDv+LosOUn4pBMkK9QyCReVovyj1jfgsrto0qO0dFTsodlbZFa0HqGveqgW5 OlgGJ2nyXHPsIXRBHsU1ggnb7P4fsj1wb+SN9kaWNUXiSDd5p7FsgK5y6QxdT3Ccc1M4NyOVbuI wWJXHwIBU2ma2lxzFNe8KUhVoc/MEZzXCB5DJ7ox3vBFRIg325ocxg4FtjSkfWU/pQNwj7xOmG8 qGYWUdq6OYxPFlllLY7y71IhbmsJ4PktmO+RHqpWH0rY6kndMJhOGlx22zMtxwnW7ILSguHLZHk Ol27JvifNn1n20+rEiHewmjuWtzDBHH7ZTplhswxWPQYFhU2+LbAIYeQFYLroGgUk90YSLtNbp2 kJyl6fgjQw9Wubnn0OO2v9+YABWA= X-Received: by 2002:a17:903:faf:b0:2ae:d09c:5241 with SMTP id d9443c01a7336-2b281715d38mr46985025ad.2.1775246183944; Fri, 03 Apr 2026 12:56:23 -0700 (PDT) X-Received: by 2002:a17:903:faf:b0:2ae:d09c:5241 with SMTP id d9443c01a7336-2b281715d38mr46984855ad.2.1775246183421; Fri, 03 Apr 2026 12:56:23 -0700 (PDT) Received: from [150.1.200.157] ([172.56.105.41]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b27497aeffsm65419065ad.43.2026.04.03.12.56.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Apr 2026 12:56:22 -0700 (PDT) Message-ID: <192dd160-d97c-4ba3-8917-a6e1bbaba6b0@redhat.com> Date: Fri, 3 Apr 2026 12:56:21 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] Allow dynamic DW_AT_bit_stride on DW_TAG_array_type To: Tom Tromey , gdb-patches@sourceware.org References: <20260320125356.1230088-1-tromey@adacore.com> From: Keith Seitz In-Reply-To: <20260320125356.1230088-1-tromey@adacore.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: rlASZeBdU9YUuCRu5LGqeTau3if3u-0zIYA9gjuxS0s_1775246185 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 Hi, On 3/20/26 5:53 AM, Tom Tromey wrote: > In Ada, it's possible to create an array where the stride is dynamic. > For example, this happens in array_of_symbolic_length.exp where GCC > emits: > > <2><143a>: Abbrev Number: 12 (DW_TAG_array_type) > <143b> DW_AT_byte_stride : 7 byte block: fd 86 13 0 0 34 1e (DW_OP_GNU_variable_value: <0x1386>; DW_OP_lit4; DW_OP_mul) > <1443> DW_AT_type : <0x13c4> > <1447> DW_AT_sibling : <0x1455> > > For gnat-llvm, though, it was more convenient to always emit a bit > stride. Using an expression for this is a DWARF extension, but it's a > fairly obvious one, and something similar is already used in gdb. > > This patch adds support for dynamic bit strides on an array to gdb. A > new test case, derived from gdb.dwarf2/arr-stride.exp (the derivation > explains the copyright dates) is included. I think this is relatively straightforward, and aside from a few minor observations, LGTM. Reviewed-By: Keith Seitz Keith > diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c > index 1d1c021a51a..e764db67f17 100644 > --- a/gdb/ada-lang.c > +++ b/gdb/ada-lang.c > @@ -3142,10 +3142,24 @@ ada_value_slice_from_ptr (struct value *array_ptr, struct type *type, > type_allocator alloc (base_index_type); > struct type *index_type > = create_static_range_type (alloc, base_index_type, low, high); > + > + dynamic_prop prop_storage; > + dynamic_prop *prop = type0->dyn_prop (DYN_PROP_BYTE_STRIDE); > + bool is_byte_stride = true; > + if (prop == nullptr) > + { > + prop = type0->dyn_prop (DYN_PROP_BIT_STRIDE); > + is_byte_stride = false; > + if (prop == nullptr) > + { > + prop = &prop_storage; > + prop->set_const_val (type0->field (0).bitsize ()); > + } > + } > + I see the above code is duplicated below -- is it worth the bother to separate into a function? Not an action item. Just a question. > struct type *slice_type = create_array_type_with_stride > (alloc, type0->target_type (), index_type, > - type0->dyn_prop (DYN_PROP_BYTE_STRIDE), > - type0->field (0).bitsize ()); > + prop, is_byte_stride); > LONGEST base_low = ada_discrete_type_low_bound (type0->index_type ()); > std::optional base_low_pos, low_pos; > CORE_ADDR base; > @@ -3177,10 +3191,24 @@ ada_value_slice (struct value *array, LONGEST low, LONGEST high) > type_allocator alloc (type->index_type ()); > struct type *index_type > = create_static_range_type (alloc, type->index_type (), low, high); > + > + dynamic_prop prop_storage; > + dynamic_prop *prop = type->dyn_prop (DYN_PROP_BYTE_STRIDE); > + bool is_byte_stride = true; > + if (prop == nullptr) > + { > + prop = type->dyn_prop (DYN_PROP_BIT_STRIDE); > + is_byte_stride = false; > + if (prop == nullptr) > + { > + prop = &prop_storage; > + prop->set_const_val (type->field (0).bitsize ()); > + } > + } > + > struct type *slice_type = create_array_type_with_stride > (alloc, type->target_type (), index_type, > - type->dyn_prop (DYN_PROP_BYTE_STRIDE), > - type->field (0).bitsize ()); > + prop, is_byte_stride); > std::optional low_pos, high_pos; > > > diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c > index 8b87d58dd9c..b216db137bc 100644 > --- a/gdb/dwarf2/read.c > +++ b/gdb/dwarf2/read.c > @@ -11483,13 +11483,13 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu) > struct type *type; > struct type *element_type, *range_type, *index_type; > const char *name; > - unsigned int bit_stride = 0; > > /* If the stride is seen and used, byte_stride_prop will be > non-NULL. In this case stride_storage will be used to store the > data locally. */ I think the above comment should now refer to `stride_prop' instead of `byte_stride_prop'. > - dynamic_prop *byte_stride_prop = nullptr; > + dynamic_prop *stride_prop = nullptr; > dynamic_prop stride_storage; > + bool is_byte_stride = true; > > element_type = die_type (die, cu); > > diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h > index 139467cfd85..da9397eddf8 100644 > --- a/gdb/gdbtypes.h > +++ b/gdb/gdbtypes.h > @@ -2518,21 +2523,21 @@ extern struct type *create_static_range_type (type_allocator &alloc, > Elements will be of type ELEMENT_TYPE, the indices will be of type > RANGE_TYPE. > > - BYTE_STRIDE_PROP, when not NULL, provides the array's byte stride. > - This byte stride property is added to the resulting array type > - as a DYN_PROP_BYTE_STRIDE. As a consequence, the BYTE_STRIDE_PROP > - argument can only be used to create types that are objfile-owned > - (see add_dyn_prop), meaning that either this function must be called > - with an objfile-owned RESULT_TYPE, or an objfile-owned RANGE_TYPE. > + STRIDE_PROP, when not NULL, provides the array's stride. If > + IS_BYTE_STRIDE is true, then this is a byte stride; when false this > + is a bit stride. This stride property is added to the resulting > + array type as a DYN_PROP_BYTE_STRIDE or a DYN_PROP_BIT_SIZE, as Should this refer to DYN_PROP_BIT_STRIDE? > + appropriate. As a consequence, the STRIDE_PROP argument can only > + be used to create types that are objfile-owned (see add_dyn_prop), > + meaning that either this function must be called with an > + objfile-owned RESULT_TYPE, or an objfile-owned RANGE_TYPE. > > - BIT_STRIDE is taken into account only when BYTE_STRIDE_PROP is NULL. > - If BIT_STRIDE is not zero, build a packed array type whose element > - size is BIT_STRIDE. Otherwise, ignore this parameter. */ > + IS_BYTE_STRIDE is ignored when STRIDE_PROP is NULL. */ > > extern struct type *create_array_type_with_stride > (type_allocator &alloc, struct type *element_type, > - struct type *range_type, struct dynamic_prop *byte_stride_prop, > - unsigned int bit_stride); > + struct type *range_type, dynamic_prop *stride_prop, > + bool is_byte_stride); > > /* Create a range type using ALLOC with a dynamic range from LOW_BOUND > to HIGH_BOUND, inclusive. INDEX_TYPE is the underlying type. BIAS