From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 122893 invoked by alias); 1 Oct 2019 19:10:07 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 122878 invoked by uid 89); 1 Oct 2019 19:10:07 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-1.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (205.139.110.61) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 01 Oct 2019 19:10:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1569957004; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=43l7V+lnAvqY/jlt51isQYkgGt+0IPoECDSrJu2oHDM=; b=EVfCw1sEI4lxv8vKiADWMvnA32TXd0WoYpYjq9RTFlHFNEq+5lYDUAVf0snP2dZs+J1396 W+c8ac5H0Rkp8vJBDiuZwrUPPYaauNLHeETid/p4pEz3LSbR2uDW9jbMugNPwaiVnUWsvQ zBO3pO3gIMsRQD/8a6ZVaJa7vGHAFmY= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-326-5S-WKI1BMDidSTYeYFcNeg-1; Tue, 01 Oct 2019 15:10:00 -0400 Received: by mail-wr1-f71.google.com with SMTP id b6so1357437wrw.2 for ; Tue, 01 Oct 2019 12:09:59 -0700 (PDT) Return-Path: Received: from ?IPv6:2001:8a0:f913:f700:56ee:75ff:fe8d:232b? ([2001:8a0:f913:f700:56ee:75ff:fe8d:232b]) by smtp.gmail.com with ESMTPSA id b16sm21371142wrh.5.2019.10.01.12.09.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Oct 2019 12:09:57 -0700 (PDT) Subject: Re: [PATCH] Change some arguments to gdb::string_view instead of name+len To: Christian Biesinger References: <20191001173345.48753-1-cbiesinger@google.com> Cc: gdb-patches From: Pedro Alves Message-ID: Date: Tue, 01 Oct 2019 19:10:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-SW-Source: 2019-10/txt/msg00034.txt.bz2 On 10/1/19 7:27 PM, Christian Biesinger via gdb-patches wrote: > On Tue, Oct 1, 2019 at 1:23 PM Pedro Alves wrote: >> >> On 10/1/19 6:33 PM, Christian Biesinger via gdb-patches wrote: >>> - if (linkage_name[len] !=3D '\0') >>> + /* Don't use string_view::operator[] because we are accessing beyond >>> + the size of the string_view, which is technically unsupported. */ >>> + if (linkage_name.data ()[linkage_name.length ()] !=3D '\0') >>> { >>> char *alloc_name; >> >> It's more than just unsupported, it's undefined behavior. If we're prom= ising >> the string_view interface, then it's supposedly valid to pass in a strin= g_view >> that happens to point just at the end of a page, with the one-past-the-e= nd >> byte living in an unmapped page. Dereferencing the one-past-end byte in >> that case SIGSEGVs. >=20 > That's true (though also a pre-existing issue). >=20 >>> - if (ms_type =3D=3D mst_file_text && startswith (name, "__gnu_compile= d")) >>> + if (ms_type =3D=3D mst_file_text && startswith (name.data (), "__gnu= _compiled")) >>> return (NULL); >>> >> >> This, via startswith also assumes that name.data() is a null-terminated >> string. >=20 > Ah yes. I'll add a startswith version that takes string_views. >=20 >> I wonder whether we should have a zstring_view type. like string_view, = but >> assumes/requires null-terminated. >=20 > How does that solve anything? This function can (apparently) take > non-null terminated strings, so zstring_view wouldn't work? Ah, right.=20=20 Hmm. I wonder then, I assume that the caller up the stack should know whether the string was originally null terminated? I wonder about tweaking the interface to pass that info down somehow. Are those cases the ones where you call strlen at the caller? Like, the interface could be: /* ... If LEN is -1, then LINKAGE_NAME is a null-terminated string. Otherwise, LINKAGE_NAME is a pointer to a string of LEN length, and not null-terminated. ... */ void symbol_set_names (struct general_symbol_info *gsymbol, const char *linkage_name, int len, int copy_name, struct objfile_per_bfd_storage *per_bfd) { So effectively, you'd be pushing the strlen call down to symbol_set_names. This goes against the idea of using string_view here, though... Thanks, Pedro Alves