From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id ED445385481A for ; Tue, 18 May 2021 15:16:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org ED445385481A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 0E975AE81; Tue, 18 May 2021 15:16:12 +0000 (UTC) Subject: Re: [RFC][gdb/cli] Ignore error in gdb command script To: Tom Tromey , Simon Marchi via Gdb-patches References: <20210518095958.GA22771@delia> <44B64C9E-9E19-47BD-80CD-0C660C7A9D94@undo.io> <453ffcaa-2a21-62a7-d449-28c7c187231a@polymtl.ca> <87im3g14ss.fsf@tromey.com> From: Tom de Vries Message-ID: Date: Tue, 18 May 2021 17:16:11 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <87im3g14ss.fsf@tromey.com> Content-Type: multipart/mixed; boundary="------------EB28BC857A5267A9C5C44A57" Content-Language: en-US X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Tue, 18 May 2021 15:16:14 -0000 This is a multi-part message in MIME format. --------------EB28BC857A5267A9C5C44A57 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit On 5/18/21 4:42 PM, Tom Tromey wrote: >>>>>> "Simon" == Simon Marchi via Gdb-patches writes: > > Simon> That sounds useful. I think that "ignore-errors" is a good initial > Simon> name, because it's clear and self-describing. We can always find and > Simon> add a short alias later. > > Fedora has shipped a Python implementation of exactly this for a while now. > So, +1 for this name and approach from me. > > One question is whether it should catch 'quit'. I tend to think not but > it should be considered. > > There is some other prior art too: > > https://sourceware.org/bugzilla/show_bug.cgi?id=8487 > > ignore-errors covers all the uses I've ever wanted personally, though, > so I think it would be fine to just go with that. However if someone is > feeling more maximal, try-catch would also be an ok addition. [ Thanks all for the feedback. Replying to latest email, CC-ing Andrew. ] Changes: - now a proper command - added error reporting - added completion - mention try-catch patch - mention pre-existing implementation on distros - mention quit behaviour. I'm doing a build & reg-test now. Thanks, - Tom --------------EB28BC857A5267A9C5C44A57 Content-Type: text/x-patch; charset=UTF-8; name="0001-gdb-cli-Add-ignore-errors-command.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; filename="0001-gdb-cli-Add-ignore-errors-command.patch" [gdb/cli] Add ignore-errors command While trying to reproduce a failing test-case from the testsuite on the command line using a gdb command script, I ran into the problem that a co= mmand failed which stopped script execution. I could work around this by splitting the script at each error, but I rea= lized it would be nice if I could tell gdb to ignore the error. A python workaround ignore-errors exists, mentioned here ( https://sourceware.org/legacy-ml/gdb/2010-06/msg00100.html ), which is already supplied by distros like Fedora and openSUSE. FTR, a more elaborate try-catch solution was posted here ( https://sourceware.org/bugzilla/show_bug.cgi?id=3D8487 ). This patch adds native ignore-errors support (so no python needed). So with this script: =2E.. $ cat script.gdb ignore-errors run echo here =2E.. we have: =2E.. $ gdb -q -batch -x script.gdb No executable file specified. Use the "file" or "exec-file" command. here$ =2E.. Note that quit is not caught: =2E.. $ gdb.sh -q (gdb) ignore-errors quit $ =2E.. which is the same behaviour as with the python implementation. gdb/ChangeLog: 2021-05-18 Tom de Vries * cli/cli-cmds.c (ignore_errors_command_completer) (ignore_errors_command): New function. (_initialize_cli_cmds): Add "ignore-errors" cmd. --- gdb/cli/cli-cmds.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 0bf418e510e..c2c3ee49eb3 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -39,6 +39,7 @@ #include "gdbsupport/filestuff.h" #include "location.h" #include "block.h" +#include "event-top.h" =20 #include "ui-out.h" #include "interps.h" @@ -2249,6 +2250,34 @@ gdb_maint_setting_str_internal_fn (struct gdbarch = *gdbarch, gdbarch); } =20 +/* Completer for "ignore-errors". */ + +static void +ignore_errors_command_completer (cmd_list_element *ignore, + completion_tracker &tracker, + const char *text, const char * /*word*/) +{ + complete_nested_command_line (tracker, text); +} + +/* Implementation of the ignore-errors command. */ + +static void +ignore_errors_command (const char *args, int from_tty) +{ + try + { + execute_command (args, from_tty); + } + catch (const gdb_exception_error &ex) + { + exception_print (gdb_stderr, ex); + + /* See also execute_gdb_command. */ + async_enable_stdin (); + } +} + void _initialize_cli_cmds (); void _initialize_cli_cmds () @@ -2618,4 +2647,12 @@ when GDB is started."), GDBINIT); c =3D add_cmd ("source", class_support, source_command, source_help_text, &cmdlist); set_cmd_completer (c, filename_completer); + + const char *ignore_errors_help_text + =3D ("Execute a single command, ignoring all errors.\n" + "Only one-line commands are supported.\n" + "This is primarily useful in scripts."); + c =3D add_cmd ("ignore-errors", class_support, ignore_errors_command, + ignore_errors_help_text, &cmdlist); + set_cmd_completer (c, ignore_errors_command_completer); } --------------EB28BC857A5267A9C5C44A57--