From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id xpRdMPnNo2AWGgAAWB0awg (envelope-from ) for ; Tue, 18 May 2021 10:23:53 -0400 Received: by simark.ca (Postfix, from userid 112) id B8FD21F11C; Tue, 18 May 2021 10:23:53 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=DKIM_SIGNED, MAILING_LIST_MULTI,RDNS_DYNAMIC,T_DKIM_INVALID,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 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 C16401E783 for ; Tue, 18 May 2021 10:23:52 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 528BA3853831; Tue, 18 May 2021 14:23:52 +0000 (GMT) Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id DE1733853831 for ; Tue, 18 May 2021 14:23:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DE1733853831 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=andrew.burgess@embecosm.com Received: by mail-wm1-x332.google.com with SMTP id u133so5539810wmg.1 for ; Tue, 18 May 2021 07:23:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=GYr7Tx1ko9XsW8VTymowX984K0rfUNdJLDSmTIKam+Q=; b=EdkvKI+go1WpdrYcSriNcIgwvGa6ZAFrYVskRXvlrfdZCnHBviQ4IgwZ66PeGWUe9p VE1mUSfcfyTH6oFNHqLhbdhXNpbr+oD+zZFBOlfLiH6H67Qa47VooiqZYe6Vt1LFt8Dd 6HyRyfa33x+vosQ7Yadf+jidtPcRZ1NITr+j4m3Wuho8Y6rP4jZX5WizYFd6EUpJR0Mh rOkhvGYIsbj9hW0fd5dvYr0ZSpKR3Juk0cCx/Fwf3z+nBDFF4iWOB5YkCryD2c2trg5l MfOGO7lbyLkPO0cF0gEZ2iWdZkaUEP14B9VOR7/LhN6/5c1GV7gzq40W63Za5a97io0O U8Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=GYr7Tx1ko9XsW8VTymowX984K0rfUNdJLDSmTIKam+Q=; b=EwuLCgV+U6Jmw6ajo6N+Zj1rOWMAQA1B7IUFTRU0pr1yocQ6E/qNIrCgaCiVdAa4vP u3+RfoNGkSNgaIJii31ZfyCohW/pRsZxXHKUi5mvpPH+dMPxLKU8JvLjxb+zr0JClw3P abd6BB1RzP3rQYyS0oGhLxIr/tB9U5i6MFe8+Y6S9egeQvy+ymdDOymtTe/RZvqic0GT aQ07IXls9kFokU8gGhAW0bp4sQvUzdF0XJpvVLLlPFiasqWvqPZCKjywCLzn5XhLbm+B qnLVpLMXHTRspYWLupl/X4LnUf9ND2gQzsKzL+ViLDBPJygZ6k1N9dWYcJHkXCgV+Kf1 aEfQ== X-Gm-Message-State: AOAM5315qIHR2lhMPIkIQ153P/pW+GliwjnBPx0ShRDf3nEXQ7T8D5nB /zG9SxJpRsSE5n944IeLwKqxfg== X-Google-Smtp-Source: ABdhPJwDKrTCuOofAbsidSnTm0zzCypVR1Aqd5PUdOA/SuAjAJq5qtNfO5UeQUxHvP0D0fT4ANqoZQ== X-Received: by 2002:a1c:ddc5:: with SMTP id u188mr5987510wmg.12.1621347827981; Tue, 18 May 2021 07:23:47 -0700 (PDT) Received: from localhost (host109-151-46-70.range109-151.btcentralplus.com. [109.151.46.70]) by smtp.gmail.com with ESMTPSA id d3sm22199455wri.75.2021.05.18.07.23.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 May 2021 07:23:47 -0700 (PDT) Date: Tue, 18 May 2021 15:23:46 +0100 From: Andrew Burgess To: Tom de Vries Subject: Re: [RFC][gdb/cli] Ignore error in gdb command script Message-ID: <20210518142346.GS3067949@embecosm.com> References: <20210518095958.GA22771@delia> <44B64C9E-9E19-47BD-80CD-0C660C7A9D94@undo.io> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: X-Operating-System: Linux/5.8.18-100.fc31.x86_64 (x86_64) X-Uptime: 15:22:12 up 15 days, 3:16, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] 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" * Tom de Vries [2021-05-18 15:57:42 +0200]: > 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. > >=20 > > As MI commands are prefixed by =E2=80=9C-=E2=80=9C, isn=E2=80=99t there= a risk of confusion? > >=20 >=20 > Ah, right, I tend to forget about MI, good point. >=20 > > There=E2=80=99s also a =E2=80=9C-=E2=80=9D command (see tui/tui-win.c) = which will stop working with > > your patch. >=20 > 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. > ... >=20 > FWIW, did not find any documentation for this command. >=20 > Anyway, the '-' prefix seems a poor choice. >=20 > I've updated the patch to implement the ignore-errors idiom natively (so > it also works without python). >=20 > Also, I've managed to fix the hang, by copying some code from > execute_gdb_command. >=20 > Thanks, > - Tom >=20 > [gdb/cli] Add ignore-errors command >=20 > 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. >=20 > 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. >=20 > 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 command > language" but I was not able to find that. >=20 > This patch adds native ignore-errors support (so no python needed). >=20 > So with this script: > ... > $ cat script.gdb > ignore-errors run > echo here > ... > we have: > ... > $ gdb -q -batch -x script.gdb > here$ > ... >=20 > We could also implement this as first-class command, like so: > ... > 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 (); } > } > ... > and: > ... > add_cmd ("ignore-errors", class_support, ignore_errors_command, > source_help_text, &cmdlist); > ... > but that means we go twice through execute_command. This seems cleaner, = at > least in that aspect. The benefit of implementing as a first class command is that we can also get command completion on the second-level command. See, for example, the existing "with" command, so I can do: (gdb) with prin and get: (gdb) with print It would be great it we got this for ignore-errors too. Thanks, Andrew >=20 > --- > gdb/event-top.c | 29 +++++++++++++++++++++++++++-- > 1 file changed, 27 insertions(+), 2 deletions(-) >=20 > 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