From: Tom Tromey Date: Tue, 25 Jul 2023 13:04:45 +0000 (-0600) Subject: Move DAP breakpoint event code to breakpoint.py X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e982d96cd601b1d4cb1bb23b3f3611ac42cca3e3;p=binutils-gdb.git Move DAP breakpoint event code to breakpoint.py A subsequent patch will add the ability to suppress breakpoint events to DAP. My first attempt at this ended up with recurse imports, causing Python failures. So, this patch moves all the DAP breakpoint event code to breakpoint.py in preparation for the change. I've renamed breakpoint_descriptor here as well, because it can now be private to breakpoint.py. --- diff --git a/gdb/python/lib/gdb/dap/breakpoint.py b/gdb/python/lib/gdb/dap/breakpoint.py index 27745ebfd2c..4a1c98efd87 100644 --- a/gdb/python/lib/gdb/dap/breakpoint.py +++ b/gdb/python/lib/gdb/dap/breakpoint.py @@ -25,6 +25,44 @@ from .startup import send_gdb_with_response, in_gdb_thread, log_stack from .typecheck import type_check +@in_gdb_thread +def _bp_modified(event): + send_event( + "breakpoint", + { + "reason": "changed", + "breakpoint": _breakpoint_descriptor(event), + }, + ) + + +@in_gdb_thread +def _bp_created(event): + send_event( + "breakpoint", + { + "reason": "new", + "breakpoint": _breakpoint_descriptor(event), + }, + ) + + +@in_gdb_thread +def _bp_deleted(event): + send_event( + "breakpoint", + { + "reason": "removed", + "breakpoint": _breakpoint_descriptor(event), + }, + ) + + +gdb.events.breakpoint_created.connect(_bp_created) +gdb.events.breakpoint_modified.connect(_bp_modified) +gdb.events.breakpoint_deleted.connect(_bp_deleted) + + # Map from the breakpoint "kind" (like "function") to a second map, of # breakpoints of that type. The second map uses the breakpoint spec # as a key, and the gdb.Breakpoint itself as a value. This is used to @@ -34,7 +72,7 @@ breakpoint_map = {} @in_gdb_thread -def breakpoint_descriptor(bp): +def _breakpoint_descriptor(bp): "Return the Breakpoint object descriptor given a gdb Breakpoint." result = { "id": bp.number, @@ -115,7 +153,7 @@ def _set_breakpoints_callback(kind, specs, creator): # Reaching this spot means success. breakpoint_map[kind][keyspec] = bp - result.append(breakpoint_descriptor(bp)) + result.append(_breakpoint_descriptor(bp)) # Exceptions other than gdb.error are possible here. except Exception as e: log_stack() diff --git a/gdb/python/lib/gdb/dap/events.py b/gdb/python/lib/gdb/dap/events.py index ab36dc559b2..10c8a34890e 100644 --- a/gdb/python/lib/gdb/dap/events.py +++ b/gdb/python/lib/gdb/dap/events.py @@ -18,7 +18,6 @@ import gdb from .server import send_event from .startup import in_gdb_thread, Invoker, log -from .breakpoint import breakpoint_descriptor from .modules import is_module, make_module @@ -35,28 +34,6 @@ def _on_exit(event): ) -@in_gdb_thread -def _bp_modified(event): - send_event( - "breakpoint", - { - "reason": "changed", - "breakpoint": breakpoint_descriptor(event), - }, - ) - - -@in_gdb_thread -def _bp_created(event): - send_event( - "breakpoint", - { - "reason": "new", - "breakpoint": breakpoint_descriptor(event), - }, - ) - - @in_gdb_thread def thread_event(event, reason): send_event( @@ -78,17 +55,6 @@ def _thread_exited(event): thread_event(event, "exited") -@in_gdb_thread -def _bp_deleted(event): - send_event( - "breakpoint", - { - "reason": "removed", - "breakpoint": breakpoint_descriptor(event), - }, - ) - - @in_gdb_thread def _new_objfile(event): if is_module(event.new_objfile): @@ -179,9 +145,6 @@ def _on_stop(event): gdb.events.stop.connect(_on_stop) gdb.events.exited.connect(_on_exit) -gdb.events.breakpoint_created.connect(_bp_created) -gdb.events.breakpoint_modified.connect(_bp_modified) -gdb.events.breakpoint_deleted.connect(_bp_deleted) gdb.events.new_thread.connect(_new_thread) gdb.events.thread_exited.connect(_thread_exited) gdb.events.cont.connect(_cont)