mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-12-18 16:57:56 +08:00
Emit stopped event for DAP attach request
In an earlier patch, I wrote:
... It also adds some machinery so that attach stops can be
suppressed, which I think is the right thing to do.
However, after some discussions here at AdaCore, I now believe this to
be incorrect -- while DAP says that expected "continue" events should
be suppressed, there is no corresponding language for expected "stop"
events, and indeed "stop" events explicitly mention cases like "step".
This patch arranges for the stop event to be emitted again.
This commit is contained in:
@@ -147,14 +147,14 @@ def _cont(event):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
_suppress_stop = False
|
_expected_stop_reason = None
|
||||||
|
|
||||||
|
|
||||||
@in_gdb_thread
|
@in_gdb_thread
|
||||||
def suppress_stop():
|
def expect_stop(reason: str):
|
||||||
"""Indicate that the next stop should not emit an event."""
|
"""Indicate that the next stop should be for REASON."""
|
||||||
global _suppress_stop
|
global _expected_stop_reason
|
||||||
_suppress_stop = True
|
_expected_stop_reason = reason
|
||||||
|
|
||||||
|
|
||||||
_expected_pause = False
|
_expected_pause = False
|
||||||
@@ -209,24 +209,22 @@ def _on_stop(event):
|
|||||||
global inferior_running
|
global inferior_running
|
||||||
inferior_running = False
|
inferior_running = False
|
||||||
|
|
||||||
global _suppress_stop
|
|
||||||
if _suppress_stop:
|
|
||||||
_suppress_stop = False
|
|
||||||
log("suppressing stop in _on_stop")
|
|
||||||
return
|
|
||||||
|
|
||||||
log("entering _on_stop: " + repr(event))
|
log("entering _on_stop: " + repr(event))
|
||||||
log(" details: " + repr(event.details))
|
if hasattr(event, "details"):
|
||||||
|
log(" details: " + repr(event.details))
|
||||||
obj = {
|
obj = {
|
||||||
"threadId": gdb.selected_thread().global_num,
|
"threadId": gdb.selected_thread().global_num,
|
||||||
"allThreadsStopped": True,
|
"allThreadsStopped": True,
|
||||||
}
|
}
|
||||||
if isinstance(event, gdb.BreakpointEvent):
|
if isinstance(event, gdb.BreakpointEvent):
|
||||||
obj["hitBreakpointIds"] = [x.number for x in event.breakpoints]
|
obj["hitBreakpointIds"] = [x.number for x in event.breakpoints]
|
||||||
|
|
||||||
global _expected_pause
|
global _expected_pause
|
||||||
# Some stop events still do not emit details. For example,
|
global _expected_stop_reason
|
||||||
# 'attach' causes a reason-less stop.
|
if _expected_stop_reason is not None:
|
||||||
if "reason" not in event.details:
|
obj["reason"] = _expected_stop_reason
|
||||||
|
_expected_stop_reason = None
|
||||||
|
elif "reason" not in event.details:
|
||||||
# This can only really happen via a "repl" evaluation of
|
# This can only really happen via a "repl" evaluation of
|
||||||
# something like "attach". In this case just emit a generic
|
# something like "attach". In this case just emit a generic
|
||||||
# stop.
|
# stop.
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import gdb
|
|||||||
# These are deprecated in 3.9, but required in older versions.
|
# These are deprecated in 3.9, but required in older versions.
|
||||||
from typing import Mapping, Optional, Sequence
|
from typing import Mapping, Optional, Sequence
|
||||||
|
|
||||||
from .events import exec_and_expect_stop, expect_process, suppress_stop
|
from .events import exec_and_expect_stop, expect_process, expect_stop
|
||||||
from .server import request, capability
|
from .server import request, capability
|
||||||
from .startup import exec_and_log, DAPException
|
from .startup import exec_and_log, DAPException
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ def attach(
|
|||||||
else:
|
else:
|
||||||
raise DAPException("attach requires either 'pid' or 'target'")
|
raise DAPException("attach requires either 'pid' or 'target'")
|
||||||
expect_process("attach")
|
expect_process("attach")
|
||||||
suppress_stop()
|
expect_stop("attach")
|
||||||
exec_and_log(cmd)
|
exec_and_log(cmd)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -28,9 +28,19 @@ if {[build_executable ${testfile}.exp $testfile] == -1} {
|
|||||||
set test_spawn_id [spawn_wait_for_attach $binfile]
|
set test_spawn_id [spawn_wait_for_attach $binfile]
|
||||||
set testpid [spawn_id_get_pid $test_spawn_id]
|
set testpid [spawn_id_get_pid $test_spawn_id]
|
||||||
|
|
||||||
# We just want to test that attaching works at all.
|
# Test that attaching works at all.
|
||||||
if {[dap_attach $testpid $binfile] != ""} {
|
set result [dap_attach $testpid $binfile]
|
||||||
dap_shutdown true
|
|
||||||
|
set found 0
|
||||||
|
foreach ev [lindex $result 1] {
|
||||||
|
if {[dict get $ev type] == "event"
|
||||||
|
&& [dict get $ev event] == "stopped"
|
||||||
|
&& [dict get $ev body reason] == "attach"} {
|
||||||
|
set found 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
gdb_assert {$found} "saw stopped event for attach"
|
||||||
|
|
||||||
|
dap_shutdown true
|
||||||
|
|
||||||
kill_wait_spawned_process $test_spawn_id
|
kill_wait_spawned_process $test_spawn_id
|
||||||
|
|||||||
Reference in New Issue
Block a user