From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 2Jx0EYcdX2HSbwAAWB0awg (envelope-from ) for ; Thu, 07 Oct 2021 12:17:11 -0400 Received: by simark.ca (Postfix, from userid 112) id 457901EE20; Thu, 7 Oct 2021 12:17:11 -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.9 required=5.0 tests=MAILING_LIST_MULTI, NICE_REPLY_A autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.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 9CCA21EDDB for ; Thu, 7 Oct 2021 12:17:10 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 588433857C6A for ; Thu, 7 Oct 2021 16:17:10 +0000 (GMT) Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 3F56C3858C60 for ; Thu, 7 Oct 2021 16:16:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3F56C3858C60 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) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id DAC0B1EDDB; Thu, 7 Oct 2021 12:16:58 -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> <2f2ce317-ae71-88b8-4b84-5eead84c376d@simark.ca> From: Simon Marchi Message-ID: <1f5c3abf-fd40-452e-26a5-34c0809b74e1@simark.ca> Date: Thu, 7 Oct 2021 12:16:58 -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: 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" On 2021-10-07 12:15 p.m., Tom de Vries via Gdb-patches wrote: > On 10/7/21 5:33 PM, Simon Marchi wrote: >>> --- 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. >> > > Ack, fixed. > >> The code LGTM, but could you write / update a test for this? > > The patch "[gdb/testsuite] Reimplement gdb.gdb/python-interrupts.exp as > unittest" uses this. It checks the output of a command that is also > throwing a "Error while executing Python code". > > Thanks, > - Tom > Ok, that's fine with me. Simon