From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 5E2AE3857357 for ; Tue, 25 Oct 2022 11:19:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5E2AE3857357 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5104722000 for ; Tue, 25 Oct 2022 11:19:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1666696786; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Er6mcbfD1c8HljD1T+ANdovv65O1KTxEysH5SneyGIE=; b=OlT4RTZtZyCB3uOXKkKh4Q4Kt/cWGxzwitU2qkG0TqPDcuxgdlOAHj2v0X22dyUXlC9nZw NUEXauJrhsWeFCEODIlmFbZQr7F8IJr6A6EsVqOvk3ou5amaoGo1bhMwebhaR1CjooZtLt Chai+E05DlDXjP6AZS7iLdSZK1BCaHw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1666696786; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Er6mcbfD1c8HljD1T+ANdovv65O1KTxEysH5SneyGIE=; b=3SNleE8dvhwf03byhlu/qjs4OrOtpoIGLUqkd1rwaXUZ8qB0oattkn7h8k2htNYJqGAlx4 KcvMqwoa9Af8oQBQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3E2D1134CA for ; Tue, 25 Oct 2022 11:19:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id GA8RDlLGV2O1dAAAMHmgww (envelope-from ) for ; Tue, 25 Oct 2022 11:19:46 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [RFC 4/5] [gdb/contrib] Add refactor_gdb_exception.py Date: Tue, 25 Oct 2022 13:19:44 +0200 Message-Id: <20221025111945.23886-5-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221025111945.23886-1-tdevries@suse.de> References: <20221025111945.23886-1-tdevries@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Add a transformation script refactor_gdb_exception.py, to be used with gdb/contrib/refactor.py that rewrites: ... catch (const gdb_exception/gdb_exception_error &VAR) { BODY; } ... using respectively CATCH_ERROR_QUIT and CATCH_ERROR. --- gdb/contrib/refactor_gdb_exception.py | 68 +++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 gdb/contrib/refactor_gdb_exception.py diff --git a/gdb/contrib/refactor_gdb_exception.py b/gdb/contrib/refactor_gdb_exception.py new file mode 100644 index 00000000000..573ec90e996 --- /dev/null +++ b/gdb/contrib/refactor_gdb_exception.py @@ -0,0 +1,68 @@ +#! /usr/bin/env python3 + +# Copyright (C) 2022 Free Software Foundation, Inc. +# +# This file is part of GDB. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Implement a refactoring transformation to handling exception catching +# using CATCH_ERROR_QUIT and CATCH_ERROR. + +import re + +pattern_lines = [ + # \1 \2 \3 + r"^([ \t]*)catch \(const (gdb_exception(?:_error)?) &([a-zA-Z0-9]+)\)", + # \4 + r"([ \t]*){(?:}|", + # \5 + r"(.*?)^\4})" +] +pattern = "\n".join(pattern_lines) + +def repl(matchobj): + global have_match + have_match = True + + g1 = matchobj.group(1) + exception = matchobj.group(2) + var = matchobj.group(3) + g4 = matchobj.group(4) + body = matchobj.group(5) + + if exception == "gdb_exception": + m = "CATCH_ERROR_QUIT" + else: + m = "CATCH_ERROR" + + if body == None or body == "": + return r"%s%s (%s, {})" % (g1, m, var) + + body = re.sub(r"\n$", r"", body) + + # Apply recursively. + body = transform(body) + + repl_lines = [ + r"%s%s (%s, {" % (g1, m, var), + r"%s" % body, + r"%s})" % g4 + ] + repl= "\n".join(repl_lines) + + return repl + +def transform(data): + return re.sub(pattern, repl, data, 0, re.MULTILINE | re.DOTALL) -- 2.35.3