From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id 44D403858296 for ; Wed, 23 Aug 2023 13:35:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 44D403858296 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: from r6.localdomain (82-217-174-174.cable.dynamic.v4.ziggo.nl [82.217.174.174]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id CA528302BBEC; Wed, 23 Aug 2023 15:35:02 +0200 (CEST) Received: by r6.localdomain (Postfix, from userid 1000) id 260A43403E8; Wed, 23 Aug 2023 15:35:02 +0200 (CEST) Message-ID: Subject: Re: [PATCH 06/10] gdb: make use of is_target_filename From: Mark Wielaard To: Andrew Burgess , gdb-patches@sourceware.org Date: Wed, 23 Aug 2023 15:35:02 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) MIME-Version: 1.0 X-Spam-Status: No, score=-3034.4 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,RCVD_IN_BARRACUDACENTRAL,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP 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: Hi Andrew, On Wed, 2023-08-16 at 16:55 +0100, Andrew Burgess wrote: > Spotted a place where is_target_filename could be used, except that > is_target_filename takes 'const char *' and in the location I spotted > we have a std::string. So I've added an overload for > is_target_filename that takes a std::string. >=20 > There should be no user visible change after this commit. This makes sense to me given that all is_target_filename really does is: return startswith (name, TARGET_SYSROOT_PREFIX); So this just moves the logic in one place. Reviewed-by: Mark Wielaard > --- > gdb/build-id.c | 2 +- > gdb/gdb_bfd.h | 8 ++++++++ > 2 files changed, 9 insertions(+), 1 deletion(-) >=20 > diff --git a/gdb/build-id.c b/gdb/build-id.c > index f68384f0197..6abf04ffacd 100644 > --- a/gdb/build-id.c > +++ b/gdb/build-id.c > @@ -90,7 +90,7 @@ build_id_to_debug_bfd_1 (const std::string &link, size_= t build_id_len, > /* lrealpath() is expensive even for the usually non-existent files. = */ > gdb::unique_xmalloc_ptr filename_holder; > const char *filename =3D nullptr; > - if (startswith (link, TARGET_SYSROOT_PREFIX)) > + if (is_target_filename (link)) > filename =3D link.c_str (); > else if (access (link.c_str (), F_OK) =3D=3D 0) > { > diff --git a/gdb/gdb_bfd.h b/gdb/gdb_bfd.h > index d15b1106d9a..5e9468dcdfd 100644 > --- a/gdb/gdb_bfd.h > +++ b/gdb/gdb_bfd.h > @@ -44,6 +44,14 @@ struct registry_accessor > =20 > int is_target_filename (const char *name); > =20 > +/* Like the above, but for std::string. */ > + > +static inline int > +is_target_filename (const std::string &name) > +{ > + return is_target_filename (name.c_str ()); > +} > + > /* Returns nonzero if the filename associated with ABFD starts with > TARGET_SYSROOT_PREFIX, zero otherwise. */ > =20