From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EDF693858C60; Mon, 11 Dec 2023 10:27:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EDF693858C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1702290429; bh=MOsisErYCQB9dTiBITt5DXTLy8GGJtUfR5gle1VbvV8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=XwWwBQlzxi+rIiL2nVxoUrkP6Me2yhb2UDm+LoHOoJKLy2mzZ2cXCfzMwaQ//fIGm OaFBLaNF6rtqp/vfjdBwyXTxC/H8qvnJRpLHTeIn8lbT+zRJmLz8igI+HZOjO3VdoF WLhhVY6O737hsj1ynVKGBVW13Sqj2zXRreGU+c68= From: "michaelwoerister at posteo dot net" To: gdb-prs@sourceware.org Subject: [Bug rust/30330] GDB 13.1 no longer prints length of Rust slice wrappers Date: Mon, 11 Dec 2023 10:27:08 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: rust X-Bugzilla-Version: 13.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: michaelwoerister at posteo dot net X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: tromey at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D30330 --- Comment #14 from Michael Woerister = --- > Notice that data_ptr points to a zero-sized struct This does not look quite right. Let's try to enumerate the cases from the ground up: - There are two kinds of unsized types in Rust: slice-like (containing `[T]= ` in some form) and dyn-objects (containing `dyn` in some form). We'll only talk about slice-like unsized types here. - A slice-like unsized value needs some kind of fat pointer that contains t= he length of the slice. An fat pointer can be `&`, `&mut`, `*const`, `*mut` an= d in debuginfo will be represented as a struct with a `data_ptr` field and a `length` field.=20 - A slice-like unsized value can either be "just the slice" (e.g. `[T]`) or= a struct with the slice type as its last field (e.g. `struct Foo { a: u32, b: u32, c: [u32] }`). An unsized struct can have any number of regular fields, i.e. it is not always zero-sized. - The slice type `[T]` in both cases will be represented by a `DW_TAG_array_type` with no count or upper bound. I'd call this array "unsi= zed" rather than "zero-sized". - In the case of just the slice, `data_ptr` will then be a regular thin poi= nter to that `DW_TAG_array_type`. - In the case of an unsized struct, the `DW_TAG_array_type` will be the typ= e of the last field. `data_ptr` will be a thin pointer to `Foo<[T]>`, i.e. it wi= ll point to the beginning of the struct, not to the unsized field. So, it sounds like the following, slightly adapted algorithm should work: - Notice a fat-pointer (it is a struct + its name starts with `&`, or `&mut= `, or `*const`, or `*mut` + it has a `data_ptr` and a `length` field). - Check the pointee type: - If it is DW_TAG_array_type, this is a "just the slice" case (e.g. `&[T]= `). Turn the fat pointer into a thin pointer of type `&[T; length]`. - If it is a struct, we expect the last field to be unsized. Note that th= is could be a vanilla `[T]` type (i.e. it would be a DW_TAG_array_type as described) OR it could be *another unsized struct* (as in `Foo>`),= so the type transformation has be applied recursively. I.e. turn the fat point= er `&Foo>` into a thin pointer `&Foo>`. Let me know what you think :) --=20 You are receiving this mail because: You are on the CC list for the bug.=