[RFC,2/3,gdb/contrib] Add refactor_require.py

Message ID 20230125200626.29340-3-tdevries@suse.de
State Committed
Headers
Series Introduce is_x86_64_m64_target |

Commit Message

Tom de Vries Jan. 25, 2023, 8:06 p.m. UTC
  Add refactoring script refactor_require.py, to be used with refactor.py.
---
 gdb/contrib/refactor_require.py | 53 +++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 gdb/contrib/refactor_require.py
  

Patch

diff --git a/gdb/contrib/refactor_require.py b/gdb/contrib/refactor_require.py
new file mode 100644
index 00000000000..e8ac96643cf
--- /dev/null
+++ b/gdb/contrib/refactor_require.py
@@ -0,0 +1,53 @@ 
+#! /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 <http://www.gnu.org/licenses/>.
+
+import re
+
+dirs = ["gdb/testsuite"]
+avoid_dir = None
+exts = [".exp"]
+
+pattern_lines = [
+    "(else)?" + re.escape ("if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {"),
+    r"\s+verbose.*",
+    r"\s+return",
+    "\}"
+]
+pattern = "\n".join(pattern_lines)
+
+def repl(matchobj):
+    global have_match
+    have_match = True
+
+    if matchobj.group(1) == "else":
+        repl_lines = [
+            r"else {",
+            r"    require is_x86_64_m64_target",
+            r"}"
+        ]
+    else:
+        repl_lines = [
+            r"require is_x86_64_m64_target"
+        ]
+    repl= "\n".join(repl_lines)
+
+    return repl
+
+def transform(data):
+    return re.sub(pattern, repl, data)