From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id vgyMNzBy2WNZgSYAWB0awg (envelope-from ) for ; Tue, 31 Jan 2023 14:55:28 -0500 Received: by simark.ca (Postfix, from userid 112) id D884A1E128; Tue, 31 Jan 2023 14:55:28 -0500 (EST) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=OpCKUM2d; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 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 85C541E0D3 for ; Tue, 31 Jan 2023 14:55:28 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 044FA3858C2B for ; Tue, 31 Jan 2023 19:55:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 044FA3858C2B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675194927; bh=WxHZJ7q7ilxruZzIQw5+cTGXxZIFmaNZE4BBw9jcWm8=; h=Date:To:Cc:Subject:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=OpCKUM2dnhbXYvki10syEEenTOSt4GV0+K8SYM/Fc3nKCPptJ2mIdQaVqQ/p5dR10 0akUCJWgaGsB1BWAnWB64oykh2Mj1dVgtMHaiYZHp80Ce3/02vOXW+tywmGwdB1qae IMehFIeNrSP3mBL3IcSFQl8ydY49xppvNpEE2j6Y= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 21A533858D28 for ; Tue, 31 Jan 2023 19:55:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 21A533858D28 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-244-78OMOw54M1eWDB2IBitNHw-1; Tue, 31 Jan 2023 14:55:04 -0500 X-MC-Unique: 78OMOw54M1eWDB2IBitNHw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3EAA23815F62; Tue, 31 Jan 2023 19:55:04 +0000 (UTC) Received: from f37-zws-nv (unknown [10.2.16.229]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EEBE340C141B; Tue, 31 Jan 2023 19:55:03 +0000 (UTC) Date: Tue, 31 Jan 2023 12:54:52 -0700 To: Pedro Alves Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] Simplify interp::exec / interp_exec - let exceptions propagate Message-ID: <20230131125452.3cec7e3d@f37-zws-nv> In-Reply-To: <20230127230545.77750-1-pedro@palves.net> References: <20230127230545.77750-1-pedro@palves.net> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII 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: Kevin Buettner via Gdb-patches Reply-To: Kevin Buettner Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" On Fri, 27 Jan 2023 23:05:45 +0000 Pedro Alves wrote: > This patch implements a simplication that I suggested here: > > https://sourceware.org/pipermail/gdb-patches/2022-March/186320.html > > Currently, the interp::exec virtual method interface is such that > subclass implementations must catch exceptions and then return them > via normal function return. > > However, higher up the in chain, for the CLI we get to > interpreter_exec_cmd, which does: > > for (i = 1; i < nrules; i++) > { > struct gdb_exception e = interp_exec (interp_to_use, prules[i]); > > if (e.reason < 0) > { > interp_set (old_interp, 0); > error (_("error in command: \"%s\"."), prules[i]); > } > } > > and for MI we get to mi_cmd_interpreter_exec, which has: > > void > mi_cmd_interpreter_exec (const char *command, char **argv, int argc) > { > ... > for (i = 1; i < argc; i++) > { > struct gdb_exception e = interp_exec (interp_to_use, argv[i]); > > if (e.reason < 0) > error ("%s", e.what ()); > } > } > > Note that if those errors are reached, we lose the original > exception's error code. I can't see why we'd want that. > > And, I can't see why we need to have interp_exec catch the exception > and return it via the normal return path. That's normally needed when > we need to handle propagating exceptions across C code, like across > readline or ncurses, but that's not the case here. > > It seems to me that we can simplify things by removing some > try/catch-ing and just letting exceptions propagate normally. > > Note, the "error in command" error shown above, which only exists in > the CLI interpreter-exec command, is only ever printed AFAICS if you > run "interpreter-exec console" when the top level interpreter is > already the console/tui. Like: > > (gdb) interpreter-exec console "foobar" > Undefined command: "foobar". Try "help". > error in command: "foobar". > > You won't see it with MI's "-interpreter-exec console" from a top > level MI interpreter: > > (gdb) > -interpreter-exec console "foobar" > &"Undefined command: \"foobar\". Try \"help\".\n" > ^error,msg="Undefined command: \"foobar\". Try \"help\"." > (gdb) > > nor with MI's "-interpreter-exec mi" from a top level MI interpreter: > > (gdb) > -interpreter-exec mi "-foobar" > ^error,msg="Undefined MI command: foobar",code="undefined-command" > ^done > (gdb) > > in both these cases because MI's -interpreter-exec just does: > > error ("%s", e.what ()); > > You won't see it either when running an MI command with the CLI's > "interpreter-exec mi": > > (gdb) interpreter-exec mi "-foobar" > ^error,msg="Undefined MI command: foobar",code="undefined-command" > (gdb) > > This last case is because MI's interp::exec implementation never > returns an error: > > gdb_exception > mi_interp::exec (const char *command) > { > mi_execute_command_wrapper (command); > return gdb_exception (); > } > > Thus I think that "error in command" error is pretty pointless, and > since it simplifies things to not have it, the patch just removes it. > > The patch also ends up addressing an old FIXME. Thanks for doing this as it'll simplify part of my "Fix gdb.base/gdb-sigterm.exp failure/error" series. LGTM. Kevin