From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id SenxCVQTX2FlbgAAWB0awg (envelope-from ) for ; Thu, 07 Oct 2021 11:33:40 -0400 Received: by simark.ca (Postfix, from userid 112) id 159DD1EE20; Thu, 7 Oct 2021 11:33:40 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.6 required=5.0 tests=MAILING_LIST_MULTI, NICE_REPLY_A,RDNS_DYNAMIC autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 7EE3D1E4A3 for ; Thu, 7 Oct 2021 11:33:39 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0FBC0385842C for ; Thu, 7 Oct 2021 15:33:39 +0000 (GMT) Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id F3AAF3858C60 for ; Thu, 7 Oct 2021 15:33:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F3AAF3858C60 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca Received: from [172.16.0.95] (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 8EEDB1E4A3; Thu, 7 Oct 2021 11:33:28 -0400 (EDT) Subject: Re: [PATCH][gdb] Make execute_command_to_string return string on throw To: Tom de Vries , gdb-patches@sourceware.org References: <20210911120202.GA16898@delia.home> From: Simon Marchi Message-ID: <2f2ce317-ae71-88b8-4b84-5eead84c376d@simark.ca> Date: Thu, 7 Oct 2021 11:33:28 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: <20210911120202.GA16898@delia.home> Content-Type: text/plain; charset=utf-8 Content-Language: tl Content-Transfer-Encoding: 7bit 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: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" > --- a/gdb/top.c > +++ b/gdb/top.c > @@ -728,13 +728,22 @@ execute_fn_to_ui_file (struct ui_file *file, std::function fn) > > /* See gdbcmd.h. */ > > -std::string > -execute_fn_to_string (std::function fn, bool term_out) > +void > +execute_fn_to_string (std::string &res, std::function fn, > + bool term_out) > { > string_file str_file (term_out); > > - execute_fn_to_ui_file (&str_file, fn); > - return std::move (str_file.string ()); > + try { > + execute_fn_to_ui_file (&str_file, fn); > + } catch (...) { > + /* Finally. */ > + res = std::move (str_file.string ()); > + throw; > + } Formatting. The code LGTM, but could you write / update a test for this? Simon