From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id BA7AC3858D1E for ; Wed, 17 May 2023 15:59:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BA7AC3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684339190; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=5eqgFYhsesrMRpV/jX4jbrdzFVl2mKbOiZVkEHcgzbY=; b=KqRZOSQRYJTgupXsxmC1xYWgjJf5MK5qI3rMdYfcTS6WiUOPD0waXeZQb2G8zy9SrQYdRD W3ayGOehRTra1UGcN/GJ5bEFT8r1JRurExPcAsViUvnA8k1BrrMtVIIUuKMsAYd3QVw9Ba foBk61UaAiAJg4UlVqckd/ahiOo6VHc= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-659-ku8uM3aNMyWobbKLT6-Jdw-1; Wed, 17 May 2023 11:59:47 -0400 X-MC-Unique: ku8uM3aNMyWobbKLT6-Jdw-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-61b78e49e99so5091426d6.1 for ; Wed, 17 May 2023 08:59:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684339187; x=1686931187; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5eqgFYhsesrMRpV/jX4jbrdzFVl2mKbOiZVkEHcgzbY=; b=cw8S5Gt+p89rOy08wakHLvIIVWLKvBNnD3dZaFFzG7iam/23xRbB2PilwNgpotRf3p Ur3toh17fD38Z9OYeXvhE559EJj9bTeINlEUhPzEmDjFjwKyeJjWfWyShbMjjKaJEfxs Djkkb9V7QKSoLng5qCX10VDXtX9geVrmAXFuGZ2v4TzXNvGkXHFj56IkKayLUizOwNme 9NZRWlNtg6lRrLIaJ39NJ8Z/2tHPhYup2jSAfxlsEAwSqgAurIeeB6EPRxpNneQbm6/l KMEpanHxuLZu9ijeaMPtxVmvBe5uJM1mfurauggNl/2HNhCl9IUA2sdQ/IqoqjyuMc4I UGrQ== X-Gm-Message-State: AC+VfDy6i7yyLOmxE6N619kfHeYxsJ0uMnzxmBReUGJceQvVxcP3+Qun f2+87lC+qqulsq0TFXS0RF3XEN7NHdfAaNZUSwk5J7JNCG3rRsRmKk3pcAapzfF+E9lifvayOLh 7iE2Z/6Y+oqNKyQGK2K0bZ/co/8E8DA== X-Received: by 2002:a05:6214:29e4:b0:5e9:2bad:c8fa with SMTP id jv4-20020a05621429e400b005e92badc8famr161453qvb.33.1684339187216; Wed, 17 May 2023 08:59:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6yn5cMrO2a8ygaa7mC2f0uLpgMrGBGGN22SayF15ta+9H5BAcsD7HVEf1xF4I7l6vypYlmbQ== X-Received: by 2002:a05:6214:29e4:b0:5e9:2bad:c8fa with SMTP id jv4-20020a05621429e400b005e92badc8famr161428qvb.33.1684339186857; Wed, 17 May 2023 08:59:46 -0700 (PDT) Received: from localhost (11.72.115.87.dyn.plus.net. [87.115.72.11]) by smtp.gmail.com with ESMTPSA id oo23-20020a05620a531700b00758fef02a08sm723195qkn.6.2023.05.17.08.59.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 May 2023 08:59:46 -0700 (PDT) From: Andrew Burgess To: Tom Tromey , gdb-patches@sourceware.org Cc: Tom Tromey Subject: Re: [PATCH] Special case "&str" in Rust parser In-Reply-To: <20230517151000.3405149-1-tom@tromey.com> References: <20230517151000.3405149-1-tom@tromey.com> Date: Wed, 17 May 2023 16:59:38 +0100 Message-ID: <87o7mj9cet.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE 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: Tom Tromey writes: > "&str" is an important type in Rust -- it's the type of string > literals. However, the compiler puts it in the DWARF in a funny way. > The slice itself is present and named "&str". However, the Rust > parser doesn't look for types with names like this, but instead tries > to construct them from components. In this case it tries to make a > pointer-to-"str" -- but "str" isn't always available, and in any case > that wouldn't yield the best result. > > This patch adds a special case for &str. > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22251 LGTM. Reviewed-By: Andrew Burgess Thanks, Andrew > --- > gdb/rust-parse.c | 10 ++++++++++ > gdb/testsuite/gdb.rust/simple.exp | 3 +++ > 2 files changed, 13 insertions(+) > > diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c > index 648e48dda40..427169611d3 100644 > --- a/gdb/rust-parse.c > +++ b/gdb/rust-parse.c > @@ -1682,6 +1682,16 @@ rust_parser::parse_slice_type () > { > assume ('&'); > > + /* Handle &str specially. This is an important type in Rust. While > + the compiler does emit the "&str" type in the DWARF, just "str" > + itself isn't always available -- but it's handy if this works > + seamlessly. */ > + if (current_token == IDENT && get_string () == "str") > + { > + lex (); > + return rust_slice_type ("&str", get_type ("u8"), get_type ("usize")); > + } > + > bool is_slice = current_token == '['; > if (is_slice) > lex (); > diff --git a/gdb/testsuite/gdb.rust/simple.exp b/gdb/testsuite/gdb.rust/simple.exp > index 08ebed3f103..a615b92ec47 100644 > --- a/gdb/testsuite/gdb.rust/simple.exp > +++ b/gdb/testsuite/gdb.rust/simple.exp > @@ -68,6 +68,9 @@ gdb_test "print simple::Unit{23}" "'}', '\.\.', or identifier expected" > gdb_test "print f" " = \"hi bob\"" > gdb_test "print fslice" " = \"bob\"" > gdb_test "print &f\[3..\]" " = \"bob\"" > +gdb_test "whatis f" "type = &str" > +gdb_test "print *(&f as *mut &str)" " = \"hi bob\"" \ > + "print via cast to &str" > > gdb_test "print g" " = \\(\\*mut \\\[u8; 6\\\]\\) $hex b\"hi bob\"" > gdb_test "ptype g" " = \\*mut \\\[u8; 6\\\]" > -- > 2.39.2