From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 3mQDM9vHo2CxFwAAWB0awg (envelope-from ) for ; Tue, 18 May 2021 09:57:47 -0400 Received: by simark.ca (Postfix, from userid 112) id C13F31F11C; Tue, 18 May 2021 09:57:47 -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.0 required=5.0 tests=MAILING_LIST_MULTI, URIBL_BLOCKED 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 D70751E783 for ; Tue, 18 May 2021 09:57:46 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 647CF3894413; Tue, 18 May 2021 13:57:46 +0000 (GMT) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id D69183835424 for ; Tue, 18 May 2021 13:57:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D69183835424 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 019D0AF80; Tue, 18 May 2021 13:57:43 +0000 (UTC) Subject: Re: [RFC][gdb/cli] Ignore error in gdb command script To: Marco Barisione References: <20210518095958.GA22771@delia> <44B64C9E-9E19-47BD-80CD-0C660C7A9D94@undo.io> From: Tom de Vries Message-ID: Date: Tue, 18 May 2021 15:57:42 +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: <44B64C9E-9E19-47BD-80CD-0C660C7A9D94@undo.io> Content-Type: multipart/mixed; boundary="------------0B07CCB8606C4116EDE9F19B" Content-Language: en-US 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: , Cc: Tom Tromey , GDB patches mailing list Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" This is a multi-part message in MIME format. --------------0B07CCB8606C4116EDE9F19B Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit On 5/18/21 1:12 PM, Marco Barisione wrote: > On 18 May 2021, at 10:59, Tom de Vries wrote: >> Hi, >> >> 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 command >> failed which stopped script execution. >> >> I could work around this by splitting the script at each error, but I realized >> it would be nice if I could tell gdb to ignore the error. >> >> Inspired by make, I chose the '-' prefix. > > As MI commands are prefixed by “-“, isn’t there a risk of confusion? > Ah, right, I tend to forget about MI, good point. > There’s also a “-” command (see tui/tui-win.c) which will stop working with > your patch. I see, that's: ... $ gdb -q -batch -ex "help -" Scroll window backward. Usage: - [N] [WIN] Scroll window WIN N lines backwards. Both WIN and N are optional, N defaults to 1, and WIN defaults to the currently focused window. ... FWIW, did not find any documentation for this command. Anyway, the '-' prefix seems a poor choice. I've updated the patch to implement the ignore-errors idiom natively (so it also works without python). Also, I've managed to fix the hang, by copying some code from execute_gdb_command. Thanks, - Tom --------------0B07CCB8606C4116EDE9F19B 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 ). This also mentions a bugzilla entry that adds "exception handling to the gdb comman= d language" but I was not able to find that. 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 here$ =2E.. We could also implement this as first-class command, like so: =2E.. static void ignore_errors_command (const char *args, int from_tty) { try { execute_command (args, from_tty); } catch (const gdb_exception_error &ex) { async_enable_stdin (); } } =2E.. and: =2E.. add_cmd ("ignore-errors", class_support, ignore_errors_command, source_help_text, &cmdlist); =2E.. but that means we go twice through execute_command. This seems cleaner, = at least in that aspect. --- gdb/event-top.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/gdb/event-top.c b/gdb/event-top.c index 002a7dc95e0..9d36b550dda 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -583,13 +583,38 @@ command_handler (const char *command) /* Do not execute commented lines. */ for (c =3D command; *c =3D=3D ' ' || *c =3D=3D '\t'; c++) ; - if (c[0] !=3D '#') + if (c[0] =3D=3D '#') + return; + + /* Detect and skip "ignore-errors". */ + const char * s =3D "ignore-errors"; + const size_t s_len =3D strlen (s); + bool ignore_errors_p + =3D (strncmp (c, s, s_len) =3D=3D 0 + && strlen (c) > s_len + && (c[s_len] =3D=3D ' ' || c[s_len] =3D=3D '\t')); + if (ignore_errors_p) { - execute_command (command, ui->instream =3D=3D ui->stdin_stream); + c +=3D s_len; + for (; *c =3D=3D ' ' || *c =3D=3D '\t'; c++) + ; + } + + try + { + execute_command (c, ui->instream =3D=3D ui->stdin_stream); =20 /* Do any commands attached to breakpoint we stopped at. */ bpstat_do_actions (); } + catch (const gdb_exception_error &ex) + { + if (!ignore_errors_p) + throw; + + /* See also execute_gdb_command. */ + async_enable_stdin (); + } } =20 /* Append RL, an input line returned by readline or one of its --------------0B07CCB8606C4116EDE9F19B--