gdb/{testsuite,system-gdbinit}: import gdb module in Python scripts

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>
This commit is contained in:
Simon Marchi
2025-10-29 13:49:14 -04:00
parent 3344d5a4aa
commit 0c830fc574
27 changed files with 57 additions and 0 deletions

View File

@@ -17,6 +17,8 @@
import os
import gdb
if "ENV_PREFIX" in os.environ:
gdb.execute("set sysroot %s" % os.environ["ENV_PREFIX"])

View 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 = []

View 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:

View 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 = []

View 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.

View File

@@ -15,6 +15,8 @@
from perftest import perftest
import gdb
class BackTrace(perftest.TestCaseWithBasicMeasurements):
def __init__(self, depth):

View File

@@ -15,6 +15,8 @@
from perftest import perftest
import gdb
class Disassemble(perftest.TestCaseWithBasicMeasurements):
def __init__(self):

View File

@@ -15,6 +15,8 @@
from perftest import perftest
import gdb
class SingleStep(perftest.TestCaseWithBasicMeasurements):
def __init__(self, step):

View File

@@ -15,6 +15,8 @@
from perftest import perftest
import gdb
class SkipCommand(perftest.TestCaseWithBasicMeasurements):
def __init__(self, name, step):

View File

@@ -18,6 +18,8 @@
from perftest import perftest
import gdb
class SkipPrologue(perftest.TestCaseWithBasicMeasurements):
def __init__(self, count):

View File

@@ -18,6 +18,8 @@
from perftest import measure, perftest
import gdb
class SolibLoadUnload1(perftest.TestCaseWithBasicMeasurements):
def __init__(self, solib_count, measure_load):

View File

@@ -15,6 +15,8 @@
from perftest import perftest
import gdb
class TemplateBreakpoints(perftest.TestCaseWithBasicMeasurements):
def __init__(self):

View 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"""

View 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)

View 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)

View 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

View File

@@ -15,6 +15,8 @@
import pathlib
import gdb
class Mapping:
def __init__(self, mapping, region):

View 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")

View File

@@ -17,6 +17,9 @@
# Breakpoints.
import gdb
class MyFinishBreakpoint(gdb.FinishBreakpoint):
def __init__(self, val, frame):
gdb.FinishBreakpoint.__init__(self, frame)

View 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):

View 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

View File

@@ -17,6 +17,8 @@
import re
import gdb
class pp_ss:
def __init__(self, val):

View 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

View File

@@ -17,6 +17,8 @@
import re
import gdb
class pp_ss:
def __init__(self, val):

View 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)

View 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

View 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