From patchwork Mon Dec 11 16:02:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 81916 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 3F083385AC30 for ; Mon, 11 Dec 2023 16:03:07 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by sourceware.org (Postfix) with ESMTPS id E91A13858C78 for ; Mon, 11 Dec 2023 16:02:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E91A13858C78 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 E91A13858C78 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::12f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702310544; cv=none; b=eiJpcIFsXwPgmtUnlXSy2575Fe/4/y58O7kv+OI4XyTVTfBVzaLL4HOuKTE1CY+lWX+kZQIk2t4sXIPJiFsevA4Wqp7PW8HPtenWFlO1wspk8jGIz1C4ZZ7QhIsxkMD0ly3hg3GV/i3GA+Vdjfm/QNX2KtpF1s0bnUb6NAJWCgo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702310544; c=relaxed/simple; bh=TuPJiDaxok7J5h9C5JDQSC46gFezfi1L0cxpelx1D84=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=XPXV/HWtUnUBWyIWNdGnybDkgTjhbxUn3jhRVhfd2LtrOCrX1ugXexUpZRKmQ9H9KN4/9lWnkZVLc6UJOTXISkjW7Gw4gdgTfD2o5ztWIeUwX26cCB6UyD+c6MaJceX/+AMFM6M8g8FA40ukPMqCIm1HGhXuHj+yRrBcqgQVTLc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x12f.google.com with SMTP id e9e14a558f8ab-35d62401a3dso18579915ab.3 for ; Mon, 11 Dec 2023 08:02:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1702310542; x=1702915342; darn=sourceware.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=iPy/1rADhqoTC7B/T/lEFi84lzFq88HdJ7wmAkR/l1E=; b=WksNmdt2CZkn3gBVGANAyJ8BZmbZGH6zGfafGcEMyFPhnb4dDnIDeO0s0oYUFEZflN Tmd99U4GiaqImLvQOOH7aHB2+QdeOs1bow6EUanaZw2YtSYf8agt6QSlW0iynJdWE0Nz TpGo8XSGB6NRihH5iwRKZYwZrYQJDJRN1hJOtTCxnPny2jNM4jAmK1z+77qKMvz9rbgU OyY4u73LI75cxbQHaTg+2doKnrGQKadtatbvQyk+Fke4y9zK3HSMGNF1f8+WLZTTWta6 c3daVSWpHrSNiMFFW1E0XHaK5pMIY5qIH0vgzBAAx8nadPFWXHJTe9U4TAmgh2Bm4nX+ ypDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702310542; x=1702915342; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iPy/1rADhqoTC7B/T/lEFi84lzFq88HdJ7wmAkR/l1E=; b=AiJL1lERXOuujTvh+WX2tsjdMOxwPLKnFYt0GgYu5o9BxeczKlVCLuiES86cmwTHS2 ZB70V64FVy2ulYgviO3pdsT5k2i81+0wfavr3ZI7O3VjsmOmMoEWUzhsYyk9wLnq3NtN 105zijPgvAzxfBo5sNRx7eyXNHxmgRdEvfPooy8piJd4zjnam5SdJa/sYwBQniNYhBsH p70fxbKr+MwfEaPb2d4yJ8/bamGo46K1ELkbfza68FDHzdmJnEfC9pTXuk+xywAj7FoR CPTjBNE+nekm5HEvWqKgHzlaj2cVfABGJtqmVoU5Nt1eOXpJCz7z+Zdz06k2OUCPS+cG 7zyg== X-Gm-Message-State: AOJu0YxARKC4QzjeAG9XuN0Cia3vsNS00dpf0blk+Hy9F6qzQ9QsU3uL n0i0EFL9aLbbp/lwD0c+ZseqCw== X-Google-Smtp-Source: AGHT+IG7RovIkReMsiXQx02IGtFa4NuLW4xEDFP4Dqbr5Ytci7u4pkPmNHd8lmy0A9O7Tr+FKwnRrg== X-Received: by 2002:a05:6e02:154b:b0:35d:a13f:dac with SMTP id j11-20020a056e02154b00b0035da13f0dacmr5963162ilu.25.1702310542090; Mon, 11 Dec 2023 08:02:22 -0800 (PST) Received: from localhost.localdomain (71-211-161-25.hlrn.qwest.net. [71.211.161.25]) by smtp.gmail.com with ESMTPSA id h25-20020a02cd39000000b0042acf934cbasm1879113jaq.72.2023.12.11.08.02.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 08:02:21 -0800 (PST) From: Tom Tromey Date: Mon, 11 Dec 2023 09:02:20 -0700 Subject: [PATCH v2 3/6] Introduce gdb.interrupt MIME-Version: 1.0 Message-Id: <20231211-dap-cancel-v2-3-db7b52cf0329@adacore.com> References: <20231211-dap-cancel-v2-0-db7b52cf0329@adacore.com> In-Reply-To: <20231211-dap-cancel-v2-0-db7b52cf0329@adacore.com> To: gdb-patches@sourceware.org Cc: Eli Zaretskii , =?utf-8?q?K=C3=A9vin_Le_Gouguec?= X-Mailer: b4 0.12.4 X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_ABUSEAT, RCVD_IN_DNSWL_NONE, RCVD_IN_XBL, 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 cancellation needs a way to interrupt whatever is happening on gdb's main thread -- whether that is the inferior, a gdb CLI command, or Python code. This patch adds a new gdb.interrupt() function for this purpose. It simply sets the quit flag and lets gdb do the rest. No tests in this patch -- instead this is tested via the DAP cancellation tests. Reviewed-By: Eli Zaretskii Reviewed-By: Kévin Le Gouguec Reviewed-By: Eli Zaretskii --- gdb/NEWS | 3 +++ gdb/doc/python.texi | 11 +++++++++++ gdb/python/python.c | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/gdb/NEWS b/gdb/NEWS index aaf8faad792..900ac47ada9 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -75,6 +75,9 @@ show remote thread-options-packet sub-classed to create handlers for objfiles with missing debug information. + ** New function gdb.interrupt(), that interrupts GDB as if the user + typed control-c. + * Debugger Adapter Protocol changes ** GDB now emits the "process" event. diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 3a35c5c2ccc..ede8b1fb6b5 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -664,6 +664,17 @@ this an easy-to-use drop-in replacement for creating threads that will work well in @value{GDBN}. @end deftp +@defun gdb.interrupt () +This causes @value{GDBN} to react as if the user had typed a control-C +character at the terminal. That is, if the inferior is running, it is +interrupted; if a @value{GDBN} command is executing, it is stopped; +and if a Python command is running, @code{KeyboardInterrupt} will be +raised. + +Unlike most Python APIs in @value{GDBN}, @code{interrupt} is +thread-safe. +@end defun + @defun gdb.post_event (event) Put @var{event}, a callable object taking no arguments, into @value{GDBN}'s internal event queue. This callable will be invoked at diff --git a/gdb/python/python.c b/gdb/python/python.c index 8a36673a3e4..832f374b39f 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1118,6 +1118,23 @@ gdbpy_post_event (PyObject *self, PyObject *args) Py_RETURN_NONE; } +/* Interrupt the current operation on the main thread. */ +static PyObject * +gdbpy_interrupt (PyObject *self, PyObject *args) +{ + { + /* Make sure the interrupt isn't delivered immediately somehow. + This probably is not truly needed, but at the same time it + seems more clear to be explicit about the intent. */ + gdbpy_allow_threads temporarily_exit_python; + scoped_disable_cooperative_sigint_handling no_python_sigint; + + set_quit_flag (); + } + + Py_RETURN_NONE; +} + /* This is the extension_language_ops.before_prompt "method". */ @@ -2678,6 +2695,8 @@ Parse String as an expression, evaluate it, and return the result as a Value." { "post_event", gdbpy_post_event, METH_VARARGS, "Post an event into gdb's event loop." }, + { "interrupt", gdbpy_interrupt, METH_NOARGS, + "Interrupt gdb's current operation." }, { "target_charset", gdbpy_target_charset, METH_NOARGS, "target_charset () -> string.\n\