From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id c0jFFiiQo2D4EgAAWB0awg (envelope-from ) for ; Tue, 18 May 2021 06:00:08 -0400 Received: by simark.ca (Postfix, from userid 112) id 49CF21F11C; Tue, 18 May 2021 06:00:08 -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.6 required=5.0 tests=MAILING_LIST_MULTI, RDNS_DYNAMIC,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 F3FC31E783 for ; Tue, 18 May 2021 06:00:05 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EC3AB3954472; Tue, 18 May 2021 10:00:04 +0000 (GMT) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 6A99C3955406 for ; Tue, 18 May 2021 10:00:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6A99C3955406 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 83A50AE92; Tue, 18 May 2021 10:00:01 +0000 (UTC) Date: Tue, 18 May 2021 11:59:59 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [RFC][gdb/cli] Ignore error in gdb command script Message-ID: <20210518095958.GA22771@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) 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 Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" 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. This demonstator works for my use case, but also has effect on the gdb prompt, which is strictly speaking not necessary. Another way to do this is to use a python workaround ignore-errors 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. This though: ... $ cat script.gdb -run echo here ... doesn't work very well: ... $ gdb -q -batch -x script.gdb here ... While this: ... $ cat script.gdb source ignore-errors.py ignore-errors run echo HERE ... works fine: ... $ gdb -q -batch -x script.gdb HERE$ ... Any comments? Thanks, - Tom [gdb/cli] Ignore error in gdb command script --- gdb/event-top.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/gdb/event-top.c b/gdb/event-top.c index 002a7dc95e0..e7dd5e1319e 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -585,7 +585,19 @@ command_handler (const char *command) ; if (c[0] != '#') { - execute_command (command, ui->instream == ui->stdin_stream); + if (*c == '-') + { + c++; + try + { + execute_command (c, ui->instream == ui->stdin_stream); + } + catch (const gdb_exception_error &ex) + { + } + } + else + execute_command (c, ui->instream == ui->stdin_stream); /* Do any commands attached to breakpoint we stopped at. */ bpstat_do_actions ();