]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/{testsuite,system-gdbinit}: import gdb module in Python scripts
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 29 Oct 2025 17:49:14 +0000 (13:49 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Thu, 30 Oct 2025 16:15:13 +0000 (12:15 -0400)
Fix flake8 warnings like:

    gdb/system-gdbinit/wrs-linux.py:21:5: F821 undefined name 'gdb'

These scripts get executed in a context where the gdb module is already
loaded, so this is not strictly necessary.  However, adding these
imports removes a lot of red lines when editing these files in an IDE.
Without them, the code uses this `gdb` thing that appears to be
undefined.  Pylance is able to pull the module definition from typeshed
[1] and provide a good experience with typings.

[1] https://github.com/python/typeshed/tree/main/stubs/gdb/gdb

Change-Id: I09c6ae1866ef66f10d8270457771687343c84e32
Approved-By: Tom Tromey <tom@tromey.com>
27 files changed:
gdb/system-gdbinit/wrs-linux.py
gdb/testsuite/gdb.base/bp-disabled-by-cond.py
gdb/testsuite/gdb.base/frame-view.py
gdb/testsuite/gdb.base/reset-catchpoint-cond.py
gdb/testsuite/gdb.base/shlib-unload.py
gdb/testsuite/gdb.perf/backtrace.py
gdb/testsuite/gdb.perf/disassemble.py
gdb/testsuite/gdb.perf/single-step.py
gdb/testsuite/gdb.perf/skip-command.py
gdb/testsuite/gdb.perf/skip-prologue.py
gdb/testsuite/gdb.perf/solib.py
gdb/testsuite/gdb.perf/template-breakpoints.py
gdb/testsuite/gdb.python/pretty-print-call-by-hand.py
gdb/testsuite/gdb.python/py-auto-load-chaining-f1.o-gdb.py
gdb/testsuite/gdb.python/py-auto-load-chaining-f2.o-gdb.py
gdb/testsuite/gdb.python/py-color-leak.py
gdb/testsuite/gdb.python/py-corefile.py
gdb/testsuite/gdb.python/py-finish-breakpoint-deletion.py
gdb/testsuite/gdb.python/py-finish-breakpoint.py
gdb/testsuite/gdb.python/py-finish-breakpoint2.py
gdb/testsuite/gdb.python/py-inferior-leak.py
gdb/testsuite/gdb.python/py-objfile-script-gdb.py
gdb/testsuite/gdb.python/py-read-memory-leak.py
gdb/testsuite/gdb.python/py-section-script.py
gdb/testsuite/gdb.python/py-watchpoint.py
gdb/testsuite/gdb.python/tui-window-factory.py
gdb/testsuite/gdb.server/fileio-packets.py

index 7db36bf64f137cf8d0930421c653eb46f5c23904..7575240cb0e923edfeb037fa2b36e02455dbb8c8 100644 (file)
@@ -17,6 +17,8 @@
 
 import os
 
+import gdb
+
 if "ENV_PREFIX" in os.environ:
     gdb.execute("set sysroot %s" % os.environ["ENV_PREFIX"])
 
index 9a939201826eb9a58a19673d6137d740fc5d51a5..7e7bade237f16a01ce04bb67a921c377c587fe83 100644 (file)
@@ -12,6 +12,7 @@
 #
 # 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 gdb
 
 bp_modified_list = []
 
index 832f3485e69668895b59db792256e384010cb835..322c2640772c509a63d2f52b03b68e03c5816f48 100644 (file)
@@ -12,6 +12,7 @@
 #
 # 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 gdb
 
 
 class Printer1:
index 9a939201826eb9a58a19673d6137d740fc5d51a5..d7a4e8d35678504ceceb529d92b2d1ebd7bd29c1 100644 (file)
@@ -13,6 +13,8 @@
 # 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 gdb
+
 bp_modified_list = []
 
 
index ec62caf586d016666568c67c0dc4f206cbfd8857..66ff7a594e3163250116f27fdd401361c6c0a0f8 100644 (file)
@@ -13,6 +13,8 @@
 # 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 gdb
+
 # Breakpoint modification events will be recorded in this dictionary.
 # The keys are the b/p numbers, and the values are the number of
 # modification events seen.
index 12f297a115a9081e4d15fa3ea4de0e8fdc84d4b7..e3d3e91418c1eee9fc1240221a82e63566b64537 100644 (file)
@@ -15,6 +15,8 @@
 
 from perftest import perftest
 
+import gdb
+
 
 class BackTrace(perftest.TestCaseWithBasicMeasurements):
     def __init__(self, depth):
index 49050c1fc1736c82427e6caaad174061898a4cf0..5705469807788d2d9f20f712db1cfca953c291e6 100644 (file)
@@ -15,6 +15,8 @@
 
 from perftest import perftest
 
+import gdb
+
 
 class Disassemble(perftest.TestCaseWithBasicMeasurements):
     def __init__(self):
index c6b1443a727959307f2779336201302643aac6ec..eecf2f982a0dcc8744223bf7002e3675685dace7 100644 (file)
@@ -15,6 +15,8 @@
 
 from perftest import perftest
 
+import gdb
+
 
 class SingleStep(perftest.TestCaseWithBasicMeasurements):
     def __init__(self, step):
index f0baf60304014b47283404ec622a183489349eb3..b344c9c36a35f6e0dc24be0047337822d00e6ed3 100644 (file)
@@ -15,6 +15,8 @@
 
 from perftest import perftest
 
+import gdb
+
 
 class SkipCommand(perftest.TestCaseWithBasicMeasurements):
     def __init__(self, name, step):
index a41b7a7a159bd032a80aee14c19926a8e3020ad1..9dd0ca7c83a39af67be48a04b758a7553b34d93f 100644 (file)
@@ -18,6 +18,8 @@
 
 from perftest import perftest
 
+import gdb
+
 
 class SkipPrologue(perftest.TestCaseWithBasicMeasurements):
     def __init__(self, count):
index 501eb6954e5ea7c0b30dcd4326d6a18076e3968f..d7266bf55bfa8dc03902a32f51ad496064ecc46b 100644 (file)
@@ -18,6 +18,8 @@
 
 from perftest import measure, perftest
 
+import gdb
+
 
 class SolibLoadUnload1(perftest.TestCaseWithBasicMeasurements):
     def __init__(self, solib_count, measure_load):
index 494d571761c995451942787694fccf165b43616c..82dc5b511a1b3c2e86752f89fccddc2642b03597 100644 (file)
@@ -15,6 +15,8 @@
 
 from perftest import perftest
 
+import gdb
+
 
 class TemplateBreakpoints(perftest.TestCaseWithBasicMeasurements):
     def __init__(self):
index 3620354548a3af6146eb4ec6f8d7683fdf153d87..48464ed72bdd2c567471a6e88d49aaeaaaea67c6 100644 (file)
@@ -14,6 +14,9 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
+import gdb
+
+
 class MytypePrinter:
     """pretty print my type"""
 
index 9641a86049eb08c5812ba97edf4a48407f33879f..7c107ec9842cba5945d201fd9348505ee603319c 100644 (file)
@@ -18,6 +18,8 @@
 
 import re
 
+import gdb
+
 print("Entering f1.o auto-load script")
 
 print("Current objfile is: %s" % gdb.current_objfile().filename)
index f1abc2cbda610b1ea41841838ab4e668203cada5..6c3311810ca0e3e56c5da2eb3d7ed7d9a4a2e48a 100644 (file)
@@ -16,6 +16,8 @@
 # This script is auto-loaded when the py-auto-load-chaining-f2.o
 # object is loaded.
 
+import gdb
+
 print("Entering f2.o auto-load script")
 
 print("Current objfile is: %s" % gdb.current_objfile().filename)
index 28afd59bfcb470eb6bc59551df7055af9d68b982..d903ee344e583165ef42da3b353d09eabc8e7153 100644 (file)
@@ -15,6 +15,8 @@
 
 import sys
 
+import gdb
+
 # Avoid generating
 # src/gdb/testsuite/gdb.python/__pycache__/gdb_leak_detector.cpython-<n>.pyc.
 sys.dont_write_bytecode = True
index bfb1c820d5dca9bfd5c602d92c62b72e3f6f8702..0ea6d71f96a0d6e5de3995c49fb349d0b449269b 100644 (file)
@@ -15,6 +15,8 @@
 
 import pathlib
 
+import gdb
+
 
 class Mapping:
     def __init__(self, mapping, region):
index 8d8ca53deaf11bd9601f84e6185789b6ca9dfdb2..d8235e3ac7dc60b0ac557d0f43065916f62c0e1c 100644 (file)
@@ -14,6 +14,9 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
+import gdb
+
+
 class MyFinishBreakpoint(gdb.FinishBreakpoint):
     def stop(self):
         print("stopped at MyFinishBreakpoint")
index 413489f68fde1af61a4cacb31fe94e124fcc3721..dd2e158c56cae687d23752aa0b76f8ac78ddba9d 100644 (file)
@@ -17,6 +17,9 @@
 # Breakpoints.
 
 
+import gdb
+
+
 class MyFinishBreakpoint(gdb.FinishBreakpoint):
     def __init__(self, val, frame):
         gdb.FinishBreakpoint.__init__(self, frame)
index ae75e518b1b49260f73f5fda9f3ea527215978ee..01d220c69705005bad19d3b6f2d445a7fec8b003 100644 (file)
@@ -16,6 +16,8 @@
 # This file is part of the GDB testsuite.  It tests python Finish
 # Breakpoints.
 
+import gdb
+
 
 class ExceptionFinishBreakpoint(gdb.FinishBreakpoint):
     def __init__(self, frame):
index bf61668532b20e92230bb3110e05cce0c94a6706..4ee4dc232ebb6169742c7d8ec2f967d530b83a9f 100644 (file)
@@ -15,6 +15,8 @@
 
 import sys
 
+import gdb
+
 # Avoid generating
 # src/gdb/testsuite/gdb.python/__pycache__/gdb_leak_detector.cpython-<n>.pyc.
 sys.dont_write_bytecode = True
index 86660741419db01de7a95b74de188ed290ef4f9e..6661700d62cca11c2437257882423df5030b9256 100644 (file)
@@ -17,6 +17,8 @@
 
 import re
 
+import gdb
+
 
 class pp_ss:
     def __init__(self, val):
index 89647cf27858a5707972fa03e0951c6e341b3c8a..a58ebfc09f7fa2861746ecdd67205abdf550c945 100644 (file)
@@ -15,6 +15,8 @@
 
 import sys
 
+import gdb
+
 # Avoid generating
 # src/gdb/testsuite/gdb.python/__pycache__/gdb_leak_detector.cpython-<n>.pyc.
 sys.dont_write_bytecode = True
index d85221e3a790b0896cd330ef14bb77307cb92b8d..fb7bef3c5c85d386b4954fc6b9cc0efc3e096a3c 100644 (file)
@@ -17,6 +17,8 @@
 
 import re
 
+import gdb
+
 
 class pp_ss:
     def __init__(self, val):
index d25826fad7c5c64e9d102dd5a3b0b0eb631951c9..9d1ea5e38b5fb14e88da784afbc222b382fcd3eb 100644 (file)
@@ -14,6 +14,9 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
+import gdb
+
+
 class MyBreakpoint(gdb.Breakpoint):
     def __init__(self):
         super().__init__("i", gdb.BP_WATCHPOINT)
index 75932147895ddddb65bc9e15d9c66a17226fb2b4..9ad75f78f48becef300987584a918dbd4d64b24c 100644 (file)
@@ -14,6 +14,9 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
+import gdb
+
+
 class TestWindow:
     def __init__(self, tui_win, msg):
         self.msg = msg
index f132e91a65dfd06fede3a1043e3dc5231d42ec31..d76cb9a7440cbfe7f6380a07817ce5e59a264c71 100644 (file)
@@ -16,6 +16,8 @@
 import os
 import stat
 
+import gdb
+
 
 # Hex encode INPUT_STRING in the same way that GDB does.  Each
 # character in INPUT_STRING is expanded to its two digit hex