aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2023-11-17 10:08:50 -0700
committerTom Tromey <tromey@adacore.com>2023-11-27 08:54:56 -0700
commitc618a1c548193d2a6a8c3d909a3d1c620a156b5d (patch)
tree17c903269c2ce3a4347f657ce576ad24e7c86599 /gdb/python
parentf087eb27651a97ca2f6350c3c48fb97fc0da9669 (diff)
downloadgdb-c618a1c548193d2a6a8c3d909a3d1c620a156b5d.zip
gdb-c618a1c548193d2a6a8c3d909a3d1c620a156b5d.tar.gz
gdb-c618a1c548193d2a6a8c3d909a3d1c620a156b5d.tar.bz2
Fix bug in DAP handling of 'pause' requests
While working on cancellation, I noticed that a DAP 'pause' request would set the "do not emit the continue" flag. This meant that a subsequent request that should provoke a 'continue' event would instead suppress the event. I then tried writing a more obvious test case for this, involving an inferior call -- and discovered that gdb.events.cont does not fire for an inferior call. This patch installs a new event listener for gdb.events.inferior_call and arranges for this to emit continue and stop events when appropriate. It also fixes the original bug, by adding a check to exec_and_expect_stop.
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/lib/gdb/dap/events.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/gdb/python/lib/gdb/dap/events.py b/gdb/python/lib/gdb/dap/events.py
index bfc3f9e..663b67e 100644
--- a/gdb/python/lib/gdb/dap/events.py
+++ b/gdb/python/lib/gdb/dap/events.py
@@ -128,8 +128,9 @@ def exec_and_expect_stop(cmd, reason):
"""Indicate that a stop is expected, then execute CMD"""
global _expected_stop
_expected_stop = reason
- global _suppress_cont
- _suppress_cont = True
+ if reason != StopKinds.PAUSE:
+ global _suppress_cont
+ _suppress_cont = True
# FIXME if the call fails should we clear _suppress_cont?
exec_and_log(cmd)
@@ -156,6 +157,26 @@ def _on_stop(event):
send_event("stopped", obj)
+# This keeps a bit of state between the start of an inferior call and
+# the end. If the inferior was already running when the call started
+# (as can happen if a breakpoint condition calls a function), then we
+# do not want to emit 'continued' or 'stop' events for the call. Note
+# that, for some reason, gdb.events.cont does not fire for an infcall.
+_infcall_was_running = False
+
+
+@in_gdb_thread
+def _on_inferior_call(event):
+ global _infcall_was_running
+ if isinstance(event, gdb.InferiorCallPreEvent):
+ _infcall_was_running = inferior_running
+ if not _infcall_was_running:
+ _cont(None)
+ else:
+ if not _infcall_was_running:
+ _on_stop(None)
+
+
gdb.events.stop.connect(_on_stop)
gdb.events.exited.connect(_on_exit)
gdb.events.new_thread.connect(_new_thread)
@@ -163,3 +184,4 @@ gdb.events.thread_exited.connect(_thread_exited)
gdb.events.cont.connect(_cont)
gdb.events.new_objfile.connect(_new_objfile)
gdb.events.free_objfile.connect(_objfile_removed)
+gdb.events.inferior_call.connect(_on_inferior_call)