Move DAP breakpoint event code to breakpoint.py
authorTom Tromey <tromey@adacore.com>
Tue, 25 Jul 2023 13:04:45 +0000 (07:04 -0600)
committerTom Tromey <tromey@adacore.com>
Tue, 1 Aug 2023 18:54:44 +0000 (12:54 -0600)
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.

gdb/python/lib/gdb/dap/breakpoint.py
gdb/python/lib/gdb/dap/events.py

index 27745ebfd2cb2a866c880cc81f7c2a48649c6cf0..4a1c98efd877e84ea7aa00e57ad77cf3d4af6c23 100644 (file)
@@ -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()
index ab36dc559b2382cc49bcc90143fa83f9a5024708..10c8a34890ed8d86e5a3041850d40b575a0edc25 100644 (file)
@@ -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)