send_event("terminated")
+# When None, a "process" event has already been sent. When a string,
+# it is the "startMethod" for that event.
+_process_event_kind = None
+
+
+@in_gdb_thread
+def send_process_event_once():
+ global _process_event_kind
+ if _process_event_kind is not None:
+ inf = gdb.selected_inferior()
+ is_local = inf.connection.type == "native"
+ data = {
+ "isLocalProcess": is_local,
+ "startMethod": _process_event_kind,
+ # Could emit 'pointerSize' here too if we cared to.
+ }
+ if inf.progspace.filename:
+ data["name"] = inf.progspace.filename
+ if is_local:
+ data["systemProcessId"] = inf.pid
+ send_event("process", data)
+ _process_event_kind = None
+
+
+@in_gdb_thread
+def expect_process(reason):
+ """Indicate that DAP is starting or attaching to a process.
+
+ REASON is the "startMethod" to include in the "process" event.
+ """
+ global _process_event_kind
+ _process_event_kind = reason
+
+
@in_gdb_thread
def thread_event(event, reason):
+ send_process_event_once()
send_event(
"thread",
{
@in_gdb_thread
def _objfile_removed(event):
+ send_process_event_once()
if is_module(event.objfile):
send_event(
"module",
# These are deprecated in 3.9, but required in older versions.
from typing import Mapping, Optional, Sequence
-from .events import exec_and_expect_stop
+from .events import exec_and_expect_stop, expect_process
from .server import request, capability
from .startup import in_gdb_thread, exec_and_log
cmd = "target remote " + target
else:
raise Exception("attach requires either 'pid' or 'target'")
+ expect_process("attach")
exec_and_log(cmd)
def config_done(**args):
global _program
if _program is not None:
+ expect_process("process")
# Suppress the continue event, but don't set any particular
# expected stop.
exec_and_expect_stop("run", None)
[list s $srcfile] $line]
dap_check_request_and_response "start inferior" configurationDone
+dap_wait_for_event_and_check "process event generated" process \
+ "body startMethod" process
dap_wait_for_event_and_check "inferior started" thread "body reason" started
set resp [lindex [dap_request_and_response evaluate {o expression [s 23]}] \