]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/testsuite: remove unused but set variables in Python files
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 29 Oct 2025 17:49:21 +0000 (13:49 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Thu, 30 Oct 2025 16:21:29 +0000 (12:21 -0400)
Fix flake8 errors like this one:

    gdb/testsuite/gdb.python/py-unwind-inline.py:61:17: F841 local variable 'v' is assigned to but never used

For this one, there is a slight possibility that removing a variable
changes some behavior, and perhaps renders some test uneffective (where
the test would no longer exercises what it meant to).  Removing a
variable means that the object it pointed to likely gets de-allocated
earlier (its tp_dealloc method gets called).  So if the intent of the
variable was to ensure the variable outlives the statements that come
after, then this change would be wrong.  But I didn't see any evidence
of that being the intent in all the occurences.

Change-Id: Ic57bc68ad225a43ae6771c47b7f443956e8029a6
Approved-By: Tom Tromey <tom@tromey.com>
gdb/testsuite/gdb.multi/multi-target-info-inferiors.py
gdb/testsuite/gdb.python/pretty-print-call-by-hand.py
gdb/testsuite/gdb.python/py-bad-printers.py
gdb/testsuite/gdb.python/py-corefile.py
gdb/testsuite/gdb.python/py-disasm.py
gdb/testsuite/gdb.python/py-frame-args.py
gdb/testsuite/gdb.python/py-pp-registration.py
gdb/testsuite/gdb.python/py-recurse-unwind.py
gdb/testsuite/gdb.python/py-unwind-inline.py
gdb/testsuite/gdb.python/tui-window-disabled.py

index 59557aee02830308df3ce8250b6d88504db733a1..3d37c724e3b200ba89f9b387ac2c800e0f2337fa 100644 (file)
@@ -54,14 +54,9 @@ def info_connections():
         print(fmt % (prefix, c.num, make_target_connection_string(c), c.description))
 
 
-def inf_num(i):
-    return i.num
-
-
 # Print information about each inferior, and the connection it is
 # using.
 def info_inferiors():
-    all_inferiors = sorted(gdb.inferiors(), key=inf_num)
     for i in gdb.inferiors():
         print(
             "Inferior %d, Connection #%d: %s"
index 48464ed72bdd2c567471a6e88d49aaeaaaea67c6..57af869fdcf1c602548ad7d6ea88e626549b312c 100644 (file)
@@ -24,7 +24,7 @@ class MytypePrinter:
         self.val = val
 
     def to_string(self):
-        calls = gdb.parse_and_eval("f()")
+        gdb.parse_and_eval("f()")
         return "mytype is %s" % self.val["x"]
 
 
index 23973ebcb4dda4166bc15ef46621c93094674385..b4f84bc695adf06023e1ab1159ef909cbf8ed8f4 100644 (file)
@@ -33,7 +33,6 @@ class BadChildrenContainerPrinter1(object):
 
     @staticmethod
     def _bad_iterator(pointer, len):
-        start = pointer
         end = pointer + len
         while pointer != end:
             yield "intentional violation of children iterator protocol"
@@ -54,7 +53,6 @@ class BadChildrenContainerPrinter2(object):
 
     @staticmethod
     def _bad_iterator(pointer, len):
-        start = pointer
         end = pointer + len
         while pointer != end:
             # The first argument is supposed to be a string.
index 0ea6d71f96a0d6e5de3995c49fb349d0b449269b..ab3d1b74d7553b54423a028e4964c19e14dec173 100644 (file)
@@ -116,7 +116,6 @@ class ShowBuildIds(gdb.Command):
             if len(b) > longest_build_id:
                 longest_build_id = len(b)
 
-        count = 0
         core_mapped_files = inf.corefile.mapped_files()
         for m in core_mapped_files:
             p = pathlib.Path(m.filename).resolve()
index 95fe9ff4117919ebba5fceb643095b5c1d7f6b30..d88c7a24f29dbbeef95a3fea330cd305bf4e03e6 100644 (file)
@@ -39,9 +39,7 @@ def builtin_disassemble_wrapper(info):
 
 def check_building_disassemble_result():
     """Check that we can create DisassembleResult objects correctly."""
-
-    result = gdb.disassembler.DisassemblerResult()
-
+    gdb.disassembler.DisassemblerResult()
     print("PASS")
 
 
@@ -230,7 +228,7 @@ class GdbErrorLateDisassembler(TestDisassembler):
     """Raise a GdbError after calling the builtin disassembler."""
 
     def disassemble(self, info):
-        result = builtin_disassemble_wrapper(info)
+        builtin_disassemble_wrapper(info)
         raise gdb.GdbError("GdbError after builtin disassembler")
 
 
@@ -238,7 +236,7 @@ class RuntimeErrorLateDisassembler(TestDisassembler):
     """Raise a RuntimeError after calling the builtin disassembler."""
 
     def disassemble(self, info):
-        result = builtin_disassemble_wrapper(info)
+        builtin_disassemble_wrapper(info)
         raise RuntimeError("RuntimeError after builtin disassembler")
 
 
@@ -261,7 +259,7 @@ class MemoryErrorLateDisassembler(TestDisassembler):
     before we return a result."""
 
     def disassemble(self, info):
-        result = builtin_disassemble_wrapper(info)
+        builtin_disassemble_wrapper(info)
         # The following read will throw an error.
         info.read_memory(1, -info.address - 1)
         return DisassemblerResult(1, "BAD")
@@ -273,7 +271,7 @@ class RethrowMemoryErrorDisassembler(TestDisassembler):
     def disassemble(self, info):
         try:
             info.read_memory(1, -info.address - 1)
-        except gdb.MemoryError as e:
+        except gdb.MemoryError:
             raise gdb.MemoryError("cannot read code at address -1")
         return DisassemblerResult(1, "BAD")
 
@@ -353,7 +351,7 @@ class GlobalCachingDisassembler(TestDisassembler):
             assert isinstance(info, gdb.disassembler.DisassembleInfo)
             assert not info.is_valid()
             try:
-                val = info.address
+                info.address
                 raise gdb.GdbError("DisassembleInfo.address is still valid")
             except RuntimeError as e:
                 assert str(e) == "DisassembleInfo is no longer valid."
@@ -363,7 +361,7 @@ class GlobalCachingDisassembler(TestDisassembler):
                 )
 
             try:
-                val = info.architecture
+                info.architecture
                 raise gdb.GdbError("DisassembleInfo.architecture is still valid")
             except RuntimeError as e:
                 assert str(e) == "DisassembleInfo is no longer valid."
@@ -373,7 +371,7 @@ class GlobalCachingDisassembler(TestDisassembler):
                 )
 
             try:
-                val = info.read_memory(1, 0)
+                info.read_memory(1, 0)
                 raise gdb.GdbError("DisassembleInfo.read is still valid")
             except RuntimeError as e:
                 assert str(e) == "DisassembleInfo is no longer valid."
@@ -542,32 +540,28 @@ class ErrorCreatingTextPart_NoArgs(TestDisassembler):
     """Try to create a DisassemblerTextPart with no arguments."""
 
     def disassemble(self, info):
-        part = info.text_part()
-        return None
+        info.text_part()
 
 
 class ErrorCreatingAddressPart_NoArgs(TestDisassembler):
     """Try to create a DisassemblerAddressPart with no arguments."""
 
     def disassemble(self, info):
-        part = info.address_part()
-        return None
+        info.address_part()
 
 
 class ErrorCreatingTextPart_NoString(TestDisassembler):
     """Try to create a DisassemblerTextPart with no string argument."""
 
     def disassemble(self, info):
-        part = info.text_part(gdb.disassembler.STYLE_TEXT)
-        return None
+        info.text_part(gdb.disassembler.STYLE_TEXT)
 
 
 class ErrorCreatingTextPart_NoStyle(TestDisassembler):
     """Try to create a DisassemblerTextPart with no string argument."""
 
     def disassemble(self, info):
-        part = info.text_part(string="abc")
-        return None
+        info.text_part(string="abc")
 
 
 class ErrorCreatingTextPart_StringAndParts(TestDisassembler):
@@ -771,8 +765,8 @@ class AnalyzingDisassembler(Disassembler):
                 idx > 0
                 and idx != nop_idx
                 and not is_nop(self._pass_1_insn[idx])
-                and self._pass_1_length[idx] > self._pass_1_length[nop_idx]
-                and self._pass_1_length[idx] % self._pass_1_length[nop_idx] == 0
+                and self._pass_1_length[idx] > nop_length
+                and self._pass_1_length[idx] % nop_length == 0
             ):
                 replace_idx = idx
                 break
@@ -786,7 +780,7 @@ class AnalyzingDisassembler(Disassembler):
                     idx > 0
                     and idx != nop_idx
                     and not is_nop(self._pass_1_insn[idx])
-                    and self._pass_1_length[idx] == self._pass_1_length[nop_idx]
+                    and self._pass_1_length[idx] == nop_length
                 ):
                     replace_idx = idx
                     break
@@ -807,7 +801,7 @@ class AnalyzingDisassembler(Disassembler):
         # is a copy of _pass_1_insn, but replace the instruction we
         # identified above with a series of 'nop' instructions.
         self._check = list(self._pass_1_insn)
-        nop_count = int(self._pass_1_length[replace_idx] / self._pass_1_length[nop_idx])
+        nop_count = int(self._pass_1_length[replace_idx] / nop_length)
         nop_insn = self._pass_1_insn[nop_idx]
         nops = [nop_insn] * nop_count
         self._check[replace_idx : (replace_idx + 1)] = nops
index 45476b1ead4418523f1d033b3418ac905a26e8ae..b72b45349ae1fc339d9f2cabc2701da609c68416 100644 (file)
@@ -23,7 +23,6 @@ class pp_s(object):
         self.val = val
 
     def to_string(self):
-        m = self.val["m"]
         return "m=<" + str(self.val["m"]) + ">"
 
 
index 4f39e426507f53f2cda6d1593aaf06620b1b8b3f..02ef2d26d476017c490fa12701cb27d7f7ceee74 100644 (file)
@@ -40,8 +40,6 @@ class pp_s1(object):
         self.val = val
 
     def to_string(self):
-        a = self.val["a"]
-        b = self.val["b"]
         return "s1 a=<" + str(self.val["a"]) + "> b=<" + str(self.val["b"]) + ">"
 
 
@@ -50,8 +48,6 @@ class pp_s2(object):
         self.val = val
 
     def to_string(self):
-        a = self.val["a"]
-        b = self.val["b"]
         return "s2 a=<" + str(self.val["a"]) + "> b=<" + str(self.val["b"]) + ">"
 
 
index 244c6939b209d6cf0395cf26748d25e798877b59..51bc600de07841bd14983e4565f01a5ea2c69c05 100644 (file)
@@ -59,20 +59,15 @@ class TestUnwinder(Unwinder):
         TestUnwinder.inc_count()
 
         if TestUnwinder.test == "check_user_reg_pc":
-            pc = pending_frame.read_register("pc")
-            pc_as_int = int(pc.cast(gdb.lookup_type("int")))
-            # gdb.write("In unwinder: pc=%x\n" % pc_as_int)
+            pending_frame.read_register("pc")
 
         elif TestUnwinder.test == "check_pae_pc":
-            pc = gdb.parse_and_eval("$pc")
-            pc_as_int = int(pc.cast(gdb.lookup_type("int")))
-            # gdb.write("In unwinder: pc=%x\n" % pc_as_int)
+            gdb.parse_and_eval("$pc")
 
         elif TestUnwinder.test == "check_undefined_symbol":
             try:
-                val = gdb.parse_and_eval("undefined_symbol")
-
-            except Exception as arg:
+                gdb.parse_and_eval("undefined_symbol")
+            except Exception:
                 pass
 
         self.recurse_level -= 1
index 1bdfd93527c09bb5b0df517fab6ff4aeb16edd2e..95310b779bd1d748d99ac192018f4946648aeb9a 100644 (file)
@@ -58,7 +58,7 @@ class dummy_unwinder(Unwinder):
         to see if the unwinder should claim it, which is never does."""
         try:
             for r in self.get_regs(pending_frame):
-                v = pending_frame.read_register(r).cast(self.void_ptr_t)
+                pending_frame.read_register(r).cast(self.void_ptr_t)
         except Exception:
             print("Dummy unwinder, exception")
             raise
index 2adde773ce8cf4125cf6869bdf9352ac20866a27..e7195eaac04476226a353b7541e847857a2a1ea6 100644 (file)
@@ -77,7 +77,6 @@ class EventWindow:
 
     def render(self):
         self._win.erase()
-        w = self._win.width
         h = self._win.height
         for i in range(min(h, len(self._events))):
             self._win.write(self._events[i] + "\n")