From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id OPqfLd+HCmj1swMAWB0awg (envelope-from ) for ; Thu, 24 Apr 2025 14:50:07 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=default header.b=npjAoU3E; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id B7B301E0C3; Thu, 24 Apr 2025 14:50:07 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=unavailable autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id AD03A1E089 for ; Thu, 24 Apr 2025 14:50:06 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 441113858D39 for ; Thu, 24 Apr 2025 18:50:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 441113858D39 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=default header.b=npjAoU3E Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 685CA3858D21 for ; Thu, 24 Apr 2025 18:48:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 685CA3858D21 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=polymtl.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 685CA3858D21 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=132.207.4.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1745520525; cv=none; b=d3W4X1KVRhRiftUo1sM3j7xyAYDzLZ1EHS0jvLkgN5zaHXkBgTsfMY10Yr++o76S4t/sR2Wvv2BYuul5ywjeIs/2Z4yOL4TCUEQEX+3l6HJFT9VX9ayf+CC1EB5AxT0xNzQGJfokt/PGQZ6Ela0hR72n8GjhFMt7IOH3pYAVxQ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1745520525; c=relaxed/simple; bh=X2x1wB7txHSItB9byDUiO3MUGhnpJkE4P+jSIvEfSrw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=FqfZ8BAzEb1vErwy3CNcDGV2fJSLA+E8iITOad70g4CSo5xfZdmvbCy5cCsoF94HQ42JWKgjTkAVBqQ0D0y3aQM35HxDr4sbASkqLqKg52o43+bju85RY+aPyU62zG9UUiWIuKjfK0SRg1SUAoaiFFfuO6/U2p5ePVdCm/7oipM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 685CA3858D21 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 53OImexv125731 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 24 Apr 2025 14:48:44 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 53OImexv125731 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=default; t=1745520525; bh=tzJCCoEapZxnPmpgaLIwEEg70PMb5PQlbIXu94wJIfA=; h=From:To:Cc:Subject:Date:From; b=npjAoU3EvuJhHdtmbysN046M3X0bJ5QUXpp2+GuXhC+wogtlcZ8XQ/DIPcZqTE/bj K8vRaXUvocjxgJM01zRO0ORX22BWSGJDX7L2LzTu5iBq/3KnVifK+yNAzk73Ssi7Wy KPaMngYbL56D914gC34bTDKMudHF9/KhmzQIKDlQ= Received: by simark.ca (Postfix, from userid 112) id 2CFDD1E10E; Thu, 24 Apr 2025 14:48:40 -0400 (EDT) Received: from simark.localdomain (modemcable238.237-201-24.mc.videotron.ca [24.201.237.238]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 089BD1E089; Thu, 24 Apr 2025 14:48:37 -0400 (EDT) From: simon.marchi@polymtl.ca To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 1/2] gdb: fix some flake8 F824 warnings Date: Thu, 24 Apr 2025 14:48:32 -0400 Message-ID: <20250424184837.2257885-1-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Thu, 24 Apr 2025 18:48:40 +0000 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org From: Simon Marchi flake8 7.2.0 appears to have this new warning: F824: global name / nonlocal name is unused: name is never assigned in scope It points out a few places in our code base where "global" is not necessary, fix them. Change-Id: Ia6fb08686977559726fefe2a5bb95d8dcb298bb0 --- gdb/python/lib/gdb/dap/__init__.py | 1 - gdb/python/lib/gdb/dap/breakpoint.py | 4 ---- gdb/python/lib/gdb/dap/events.py | 1 - gdb/python/lib/gdb/dap/frames.py | 6 +----- gdb/python/lib/gdb/dap/globalvars.py | 1 - gdb/python/lib/gdb/dap/launch.py | 1 - gdb/python/lib/gdb/dap/scopes.py | 3 --- gdb/python/lib/gdb/dap/server.py | 11 ----------- gdb/python/lib/gdb/dap/sources.py | 3 --- gdb/python/lib/gdb/dap/varref.py | 3 +-- gdb/python/lib/gdb/styling.py | 1 - gdb/testsuite/analyze-racy-logs.py | 3 --- 12 files changed, 2 insertions(+), 36 deletions(-) diff --git a/gdb/python/lib/gdb/dap/__init__.py b/gdb/python/lib/gdb/dap/__init__.py index f908c9199817..1c3cf8e07790 100644 --- a/gdb/python/lib/gdb/dap/__init__.py +++ b/gdb/python/lib/gdb/dap/__init__.py @@ -96,5 +96,4 @@ def pre_command_loop(): # These are handy for bug reports. startup.exec_and_log("show version") startup.exec_and_log("show configuration") - global server startup.start_dap(server.main_loop) diff --git a/gdb/python/lib/gdb/dap/breakpoint.py b/gdb/python/lib/gdb/dap/breakpoint.py index bfb7bd3b05c9..59da12030678 100644 --- a/gdb/python/lib/gdb/dap/breakpoint.py +++ b/gdb/python/lib/gdb/dap/breakpoint.py @@ -51,7 +51,6 @@ def suppress_new_breakpoint_event(): @in_gdb_thread def _bp_modified(event): - global _suppress_bp if not _suppress_bp: send_event( "breakpoint", @@ -64,7 +63,6 @@ def _bp_modified(event): @in_gdb_thread def _bp_created(event): - global _suppress_bp if not _suppress_bp: send_event( "breakpoint", @@ -77,7 +75,6 @@ def _bp_created(event): @in_gdb_thread def _bp_deleted(event): - global _suppress_bp if not _suppress_bp: send_event( "breakpoint", @@ -151,7 +148,6 @@ def _remove_entries(table, *names): # the breakpoint. @in_gdb_thread def _set_breakpoints_callback(kind, specs, creator): - global breakpoint_map # Try to reuse existing breakpoints if possible. if kind in breakpoint_map: saved_map = breakpoint_map[kind] diff --git a/gdb/python/lib/gdb/dap/events.py b/gdb/python/lib/gdb/dap/events.py index 54caea0ee864..4dc9d65e53e1 100644 --- a/gdb/python/lib/gdb/dap/events.py +++ b/gdb/python/lib/gdb/dap/events.py @@ -238,7 +238,6 @@ def _on_stop(event): ): obj["reason"] = "pause" else: - global stop_reason_map obj["reason"] = stop_reason_map[event.details["reason"]] _expected_pause = False send_event_maybe_later("stopped", obj) diff --git a/gdb/python/lib/gdb/dap/frames.py b/gdb/python/lib/gdb/dap/frames.py index 6433dbe8d05f..4dacb87400ab 100644 --- a/gdb/python/lib/gdb/dap/frames.py +++ b/gdb/python/lib/gdb/dap/frames.py @@ -53,12 +53,11 @@ gdb.events.cont.connect(_clear_frame_ids) @in_gdb_thread def frame_for_id(id): """Given a frame identifier ID, return the corresponding frame.""" - global thread_ids if id in thread_ids: thread_id = thread_ids[id] if thread_id != gdb.selected_thread().global_num: set_thread(thread_id) - global _all_frames + return _all_frames[id] @@ -103,10 +102,8 @@ def _frame_id_generator(): # Helper function to assign an ID to a frame. def get_id(frame): - global _all_frames num = len(_all_frames) _all_frames.append(frame) - global thread_ids thread_ids[num] = gdb.selected_thread().global_num return num @@ -128,7 +125,6 @@ def _frame_id_generator(): @in_gdb_thread def _get_frame_iterator(): thread_id = gdb.selected_thread().global_num - global _iter_map if thread_id not in _iter_map: _iter_map[thread_id] = _MemoizingIterator(_frame_id_generator()) return _iter_map[thread_id] diff --git a/gdb/python/lib/gdb/dap/globalvars.py b/gdb/python/lib/gdb/dap/globalvars.py index 2e4b2a6091d5..9d64d288d2a6 100644 --- a/gdb/python/lib/gdb/dap/globalvars.py +++ b/gdb/python/lib/gdb/dap/globalvars.py @@ -78,7 +78,6 @@ def get_global_scope(frame): except RuntimeError: return None - global _id_to_scope block = block.static_block if block in _id_to_scope: return _id_to_scope[block] diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py index e093e602d278..8ac4c7750c61 100644 --- a/gdb/python/lib/gdb/dap/launch.py +++ b/gdb/python/lib/gdb/dap/launch.py @@ -164,7 +164,6 @@ def attach( @request("configurationDone", on_dap_thread=True) def config_done(**args): # Handle the launch or attach. - global _launch_or_attach_promise if _launch_or_attach_promise is None: raise DAPException("launch or attach not specified") # Resolve the launch or attach, but only after the diff --git a/gdb/python/lib/gdb/dap/scopes.py b/gdb/python/lib/gdb/dap/scopes.py index f499dcbba920..7ce3a7fcfe58 100644 --- a/gdb/python/lib/gdb/dap/scopes.py +++ b/gdb/python/lib/gdb/dap/scopes.py @@ -120,7 +120,6 @@ class _FinishScopeReference(_ScopeReference): def fetch_one_child(self, idx): assert idx == 0 - global _last_return_value return ("(return)", _last_return_value) @@ -145,8 +144,6 @@ class _RegisterReference(_ScopeReference): @request("scopes") def scopes(*, frameId: int, **extra): - global _last_return_value - global frame_to_scope if frameId in frame_to_scope: scopes = frame_to_scope[frameId] else: diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py index d4314e828041..c4fa78183468 100644 --- a/gdb/python/lib/gdb/dap/server.py +++ b/gdb/python/lib/gdb/dap/server.py @@ -307,7 +307,6 @@ class Server: args = {} def fn(): - global _commands return _commands[params["command"]](**args) self.invoke_request(req, result, fn) @@ -440,7 +439,6 @@ def send_event(event, body=None): """Send an event to the DAP client. EVENT is the name of the event, a string. BODY is the body of the event, an arbitrary object.""" - global _server _server.send_event(event, body) @@ -449,13 +447,11 @@ def send_event_maybe_later(event, body=None): within the dap thread and that request is configured to delay the event, wait until the response has been sent until the event is sent back to the client.""" - global _server _server.send_event_maybe_later(event, body) def call_function_later(fn): """Call FN later -- after the current request's response has been sent.""" - global _server _server.call_function_later(fn) @@ -533,7 +529,6 @@ def request( if response: if defer_stop_events: - global _server if _server is not None: with _server.delayed_events_lock: _server.defer_stop_events = True @@ -555,7 +550,6 @@ def request( if expect_stopped: cmd = _check_not_running(cmd) - global _commands assert name not in _commands _commands[name] = cmd return cmd @@ -568,7 +562,6 @@ def capability(name, value=True): the DAP capability NAME.""" def wrap(func): - global _capabilities assert name not in _capabilities _capabilities[name] = value return func @@ -581,7 +574,6 @@ def client_bool_capability(name, default=False): If the capability was not specified, or did not have boolean type, DEFAULT is returned. DEFAULT defaults to False.""" - global _server if name in _server.config and isinstance(_server.config[name], bool): return _server.config[name] return default @@ -589,7 +581,6 @@ def client_bool_capability(name, default=False): @request("initialize", on_dap_thread=True) def initialize(**args): - global _server, _capabilities _server.config = args _server.send_event_later("initialized") global _lines_start_at_1 @@ -705,7 +696,6 @@ def export_line(line: int) -> int: """Rewrite LINE according to client capability. This applies the linesStartAt1 capability as needed, when sending a line number from gdb to the client.""" - global _lines_start_at_1 if not _lines_start_at_1: # In gdb, lines start at 1, so we only need to change this if # the client starts at 0. @@ -717,7 +707,6 @@ def import_line(line: int) -> int: """Rewrite LINE according to client capability. This applies the linesStartAt1 capability as needed, when the client sends a line number to gdb.""" - global _lines_start_at_1 if not _lines_start_at_1: # In gdb, lines start at 1, so we only need to change this if # the client starts at 0. diff --git a/gdb/python/lib/gdb/dap/sources.py b/gdb/python/lib/gdb/dap/sources.py index 938c93a88903..625c01f5d12d 100644 --- a/gdb/python/lib/gdb/dap/sources.py +++ b/gdb/python/lib/gdb/dap/sources.py @@ -37,7 +37,6 @@ def make_source(fullname, filename=None): FILENAME is the base name; if None (the default), then it is computed from FULLNAME. """ - global _source_map if fullname in _source_map: result = _source_map[fullname] else: @@ -53,7 +52,6 @@ def make_source(fullname, filename=None): global _next_source result["sourceReference"] = _next_source - global _id_map _id_map[_next_source] = result _next_source += 1 @@ -71,7 +69,6 @@ def decode_source(source): if "sourceReference" not in source: raise DAPException("either 'path' or 'sourceReference' must appear in Source") ref = source["sourceReference"] - global _id_map if ref not in _id_map: raise DAPException("no sourceReference " + str(ref)) return _id_map[ref]["path"] diff --git a/gdb/python/lib/gdb/dap/varref.py b/gdb/python/lib/gdb/dap/varref.py index 42b53027531d..8a13c51a4523 100644 --- a/gdb/python/lib/gdb/dap/varref.py +++ b/gdb/python/lib/gdb/dap/varref.py @@ -69,7 +69,6 @@ class BaseReference(ABC): NAME is a string or None. None means this does not have a name, e.g., the result of expression evaluation.""" - global all_variables all_variables.append(self) self._ref = len(all_variables) self._name = name @@ -267,7 +266,7 @@ class VariableReference(BaseReference): @in_gdb_thread def find_variable(ref): """Given a variable reference, return the corresponding variable object.""" - global all_variables + # Variable references are offset by 1. ref = ref - 1 if ref < 0 or ref > len(all_variables): diff --git a/gdb/python/lib/gdb/styling.py b/gdb/python/lib/gdb/styling.py index e9387e3a0d36..60c470f7348e 100644 --- a/gdb/python/lib/gdb/styling.py +++ b/gdb/python/lib/gdb/styling.py @@ -80,7 +80,6 @@ try: # ignore. pass - global _asm_lexers if lexer_type not in _asm_lexers: _asm_lexers[lexer_type] = lexers.get_lexer_by_name(lexer_type) _asm_lexers[lexer_type].add_filter(HandleNasmComments()) diff --git a/gdb/testsuite/analyze-racy-logs.py b/gdb/testsuite/analyze-racy-logs.py index e7c56471cd87..f24bea9d3fcd 100755 --- a/gdb/testsuite/analyze-racy-logs.py +++ b/gdb/testsuite/analyze-racy-logs.py @@ -62,7 +62,6 @@ sum_matcher = re.compile("^(.?(PASS|FAIL)): (.*)$") def parse_sum_line(line: str, dic: dict[str, set[str]]): """Parse a single LINE from a sumfile, and store the results in the dictionary referenced by DIC.""" - global sum_matcher line = line.rstrip() m = re.match(sum_matcher, line) @@ -96,7 +95,6 @@ def read_sum_files(files: list[str]): """Read the sumfiles (passed as a list in the FILES variable), and process each one, filling the FILES_AND_TESTS global dictionary with information about them.""" - global files_and_tests for x in files: with open(x, "r") as f: @@ -115,7 +113,6 @@ def identify_racy_tests(): This function does that for all sets (PASS, FAIL, KPASS, KFAIL, etc.), and then print a sorted list (without duplicates) of all the tests that were found to be racy.""" - global files_and_tests # First, construct two dictionaries that will hold one set of # testcases for each state (PASS, FAIL, etc.). base-commit: 0ad5b8a3b7cd2cfbdef3a3cbe45975b6d027a283 -- 2.49.0