From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id YLesBC0dX2HSbwAAWB0awg (envelope-from ) for ; Thu, 07 Oct 2021 12:15:41 -0400 Received: by simark.ca (Postfix, from userid 112) id 110241EE20; Thu, 7 Oct 2021 12:15:41 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,NICE_REPLY_A,URIBL_BLOCKED autolearn=unavailable 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 C18391EDDB for ; Thu, 7 Oct 2021 12:15:40 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4283E3858026 for ; Thu, 7 Oct 2021 16:15:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4283E3858026 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1633623340; bh=VgBD+tpIjDsWmwqw6aJ+/1au1LG0cK1FglTwDidRwbA=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=MkDDbPD1ASnbvjOWwuuGwfKXYaVkHBwko3R0qkjlq8NAVCdxNJzlYoH9NlDiEcKtZ SHRqH9IAtTDBa+foPndOldJrquErxMg3tllzq/RLI6eJ/fvIRU0jgndaTZhvwiwuxr 0GBGnRbWY9Io9VcVvIc789LhQh2sFqflQv+gOzsA= Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id E6F7F3858C60 for ; Thu, 7 Oct 2021 16:15:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E6F7F3858C60 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 348C1224B8; Thu, 7 Oct 2021 16:15:20 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1C83913BB1; Thu, 7 Oct 2021 16:15:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mRYhBRgdX2FuFQAAMHmgww (envelope-from ); Thu, 07 Oct 2021 16:15:20 +0000 Subject: Re: [PATCH][gdb] Make execute_command_to_string return string on throw To: Simon Marchi , gdb-patches@sourceware.org References: <20210911120202.GA16898@delia.home> <2f2ce317-ae71-88b8-4b84-5eead84c376d@simark.ca> Message-ID: Date: Thu, 7 Oct 2021 18:15:19 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <2f2ce317-ae71-88b8-4b84-5eead84c376d@simark.ca> Content-Type: text/plain; charset=utf-8 Content-Language: en-US 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: , From: Tom de Vries via Gdb-patches Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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