From patchwork Tue Nov 14 19:25:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 79872 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8D9663858C42 for ; Tue, 14 Nov 2023 19:25:46 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) by sourceware.org (Postfix) with ESMTPS id 5C9823858D37 for ; Tue, 14 Nov 2023 19:25:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5C9823858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5C9823858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d30 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699989935; cv=none; b=CzSSQmn1LI1vrq0QNeHQOwTvkMqzEDusufZm/YP9CM/htxOb7mu79avvC7dEN4mmchaxZCBJKAW1mJfNEpZlpuEIs0KPkoB+GzF1Zio/hrAdBGSXoBvisA8GJ8jFAPp94E1Bkq2uxYAzHWOQLwxwHl5EYFVcUETtTcwCZGr9Vuw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699989935; c=relaxed/simple; bh=Bb+qaw6kcVV2UspikYel1EhHnMDa5ZNSaonrynW6wG0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=oFarADVEKIoAN0F36JGMIne/JOhGv5qzQ38FGPYYgHB6F/WR4HxJUKro6h2HpRwHs0C7AfAZFDfM4EyhwhbLCohCxF+PU/j2rU4oTIvhC3t0sSsbeQTHET6bnmlBNHBcPANhVRx8Z0OD6C2pugIhQM+bS33hKUnfKvaBkm5bHcs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-io1-xd30.google.com with SMTP id ca18e2360f4ac-7a92727934eso235847039f.3 for ; Tue, 14 Nov 2023 11:25:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1699989932; x=1700594732; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Sodvl8fpSlHh/7rv97As7XGCkKyeDhWoENe1rzoIVV0=; b=jjvuMV88gCTX2y9HpM8hj8DVXGy6df9rWB8CkhZPzexHZutRBsvGHgwhwSVwwgOEYV RethUAfdL3VItbid20rgV3FbC+Aep8Q81dlDwBtXSubW71HJMLS1eUwQ5E1tQRo8ORHX 5FFfBPKNyQObmJRjhWPTgJVrfkOyOGzbjG56Yl1Vp+Wc9T9W8QyqWigROyl6bM1o7WCO qABdMz+8gEdgClGO78bEOlOddvSHb95HhIhzbzbwU/XTIFRvvnck1QI/kXmwJvTThB+B 6jIzGs5lGcHVvdglTB/6td4aAHjusLu4iHhcgyphjj5eTcluB0yV0lnDigYJwQNabCdV T+fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699989932; x=1700594732; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Sodvl8fpSlHh/7rv97As7XGCkKyeDhWoENe1rzoIVV0=; b=KjfEo3I21DxB/WoKy0Nnx8cOjDpWRSYGcTqqQmnIUk0uAMGWaj+kxVD0+WIBv4Pvuu apLx18efNb9u0i1XMUUf2yhNXVFMLHgOsn8snf/0n5N7rUg83UU198hnoz6m/p8umq/Q 9A+Lussp1SRL4wudQbWPraL5SdYwtT2Qdf1tRM9y5rQLjLQocMmLXjQ+BuaWv074smI5 KEVK98JEQUR1/wqWIJ23n7S6TTbI6AH6bfOtVkEsrUb3QQUKHwJsVFzLmhyez1RcLp61 ecsgMMvYK8XFscFqNov4HrCexhwBzTdArVDVDI0mSUWeovRrBKzjYc6506hbGwiuPNT/ RAzA== X-Gm-Message-State: AOJu0YyBtxF2gXSBxvoDUPtLezfGLswI5cCb8Qy2ee2uZ2VGgRhDvjDS 04uCWEJcPlDWg957ysKdi+NKVtAJy/dk7qTkALZznA== X-Google-Smtp-Source: AGHT+IHSQuUXqytTvQF4q0GcypjstwuLvXxZihCca4frstucCnApAl9C/6HdqXTGvk2/WzDbAZWXPw== X-Received: by 2002:a6b:f203:0:b0:783:62d0:88c with SMTP id q3-20020a6bf203000000b0078362d0088cmr11607666ioh.19.1699989932505; Tue, 14 Nov 2023 11:25:32 -0800 (PST) Received: from localhost.localdomain (97-122-77-73.hlrn.qwest.net. [97.122.77.73]) by smtp.gmail.com with ESMTPSA id s11-20020a056638258b00b0041f552e4aa2sm526899jat.135.2023.11.14.11.25.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 11:25:32 -0800 (PST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Emit DAP "process" event Date: Tue, 14 Nov 2023 12:25:21 -0700 Message-ID: <20231114192521.3710322-1-tromey@adacore.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org DAP specifies a "process" event that is sent when a process is started or attached to. gdb was not emitting this (several DAP clients appear to ignore it entirely), but it looked easy and harmless to implement. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30473 --- gdb/python/lib/gdb/dap/events.py | 36 ++++++++++++++++++++++++++++++++ gdb/python/lib/gdb/dap/launch.py | 4 +++- gdb/testsuite/gdb.dap/pause.exp | 2 ++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/gdb/python/lib/gdb/dap/events.py b/gdb/python/lib/gdb/dap/events.py index e9ddcab135f..2c0d08cf653 100644 --- a/gdb/python/lib/gdb/dap/events.py +++ b/gdb/python/lib/gdb/dap/events.py @@ -35,8 +35,43 @@ def _on_exit(event): 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", { @@ -70,6 +105,7 @@ def _new_objfile(event): @in_gdb_thread def _objfile_removed(event): + send_process_event_once() if is_module(event.objfile): send_event( "module", diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py index d13037fa476..84ff1b4aadb 100644 --- a/gdb/python/lib/gdb/dap/launch.py +++ b/gdb/python/lib/gdb/dap/launch.py @@ -18,7 +18,7 @@ import gdb # These are deprecated in 3.9, but required in older versions. from typing import Mapping, Optional, Sequence -from .events import ExecutionInvoker +from .events import ExecutionInvoker, expect_process from .server import request, capability from .startup import send_gdb, send_gdb_with_response, in_gdb_thread, exec_and_log @@ -77,6 +77,7 @@ def attach(*, pid: Optional[int] = None, target: Optional[str] = None, **args): cmd = "target remote " + target else: raise Exception("attach requires either 'pid' or 'target'") + send_gdb(lambda: expect_process("attach")) # Use send_gdb_with_response to ensure we get an error if the # attach fails. send_gdb_with_response(cmd) @@ -88,6 +89,7 @@ def attach(*, pid: Optional[int] = None, target: Optional[str] = None, **args): def config_done(**args): global _program if _program is not None: + send_gdb(lambda: expect_process("process")) # Suppress the continue event, but don't set any particular # expected stop. send_gdb(ExecutionInvoker("run", None)) diff --git a/gdb/testsuite/gdb.dap/pause.exp b/gdb/testsuite/gdb.dap/pause.exp index 27955d31526..b16b294be77 100644 --- a/gdb/testsuite/gdb.dap/pause.exp +++ b/gdb/testsuite/gdb.dap/pause.exp @@ -30,6 +30,8 @@ if {[dap_launch $testfile] == ""} { } 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 dap_check_request_and_response pause pause \