From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 0CB6C3858D1E for ; Mon, 18 Apr 2022 20:11:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0CB6C3858D1E Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 23IKBl05010274 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Apr 2022 16:11:52 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 23IKBl05010274 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 737531E150; Mon, 18 Apr 2022 16:11:47 -0400 (EDT) Message-ID: <3fab15b9-7d48-c5c7-4c94-e481c30d9848@polymtl.ca> Date: Mon, 18 Apr 2022 16:11:47 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH 2/5] gdbsupport: make gdb_abspath return an std::string Content-Language: en-US To: Tom Tromey , Simon Marchi via Gdb-patches Cc: Simon Marchi References: <20220414200137.3479373-1-simon.marchi@polymtl.ca> <20220414200137.3479373-2-simon.marchi@polymtl.ca> <8735iauql1.fsf@tromey.com> From: Simon Marchi In-Reply-To: <8735iauql1.fsf@tromey.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Mon, 18 Apr 2022 20:11:47 +0000 X-Spam-Status: No, score=-3034.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Apr 2022 20:11:55 -0000 On 2022-04-18 15:41, Tom Tromey wrote: >>>>>> "Simon" == Simon Marchi via Gdb-patches writes: > > Simon> From: Simon Marchi > Simon> I'm trying to switch these functions to use std::string instead of char > Simon> arrays, as much as possible. Some callers benefit from it (can avoid > Simon> doing a copy of the result), while others suffer (have to make one more > Simon> copy). > > I hate copies but the main thing is to make sure none of them are in hot > paths. This seems fine on that front. > > Sometimes I wonder if gdb would be better off with its own string type > -- say a combination of gdb::unique_xmalloc_ptr and string_view. > This would interact more nicely with legacy code without sacrificing C++ > string methods. We could stick the string length in there as well if we > thought that was worthwhile. Yeah, we'll always be stuck with APIs (system or otherwise) that hand us strings that we need free (so, use gdb::unique_xmalloc_ptr). And as far as I know there's no way of building an std::string that would take ownership of the malloc'ed char array. We would have no choice but to make a copy if we wanted to build an std::string out of it. So having our own string type that could do that would be a plus. On the other hand, the day we use an API that returns an std::string, we won't be able to build our string type from the std::string without copying it... Simon