From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by sourceware.org (Postfix) with ESMTPS id 16FBE385840B for ; Mon, 16 Oct 2023 11:50:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 16FBE385840B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 16FBE385840B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::132 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697457058; cv=none; b=cVluasPv8kYQwTH2luKQSratW/nYR0Ou5wROK0g57i1QdWqtSB4RHkgrwCso9tAbMLZ9ymOxvtxnZj+hiwmPZPBVwf+vZU9hkZB38t6FpYv59rhixP20WmQI1bYtWvarlJb1eMKkHhZrsLXg8xZYqXg6pLc0wWfHNSy3DhhojlQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697457058; c=relaxed/simple; bh=antl33cf0/S9NACRXjhCze1OkjWcHq9iuyeEQ5agP4s=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=aOjgBzvADzEQ/ca24oz8APmowcIQuDMKN6tN/31Ipf21m4OjqAPo+yPRTJnWYwcpye5h+0hUpCBJRbpWTbNZ8QZIhB142/882e/wIwCdrtgmyImht6w1BiyjgRNdejg86yaaKh0l0WXHi6LtGrgB67s27UHyqV5pwgl8GZ3i7F0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-507a62d4788so2341335e87.0 for ; Mon, 16 Oct 2023 04:50:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697457045; x=1698061845; 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=/+oyrZtV1tuM3la1krVprs4qQRZBG6K/5KIJZPiYmoo=; b=A87itkYL2eCOw3o7N+OX38ZgSOUr4QlwInxdBktq0eeC8H88co8Fgegiz5kelE+Blr 1DBVQz5PTaM97yXgVqkLg9zhBEQLYoI0rch+igySph+eX6RPYI7onhWuIlkXtO9zKf5v uDPzHgkBRDOxFN13//qCuLck+72ohPit75Ed4i/vZYMjiT6pXRPVG7+VTkA26qkZnT8L 0VDeUoaIyoiwaMHB52LyntSJSwYuAX5Cfx1TLGXuufFkIPaSO3GhG6X12nRr20XBANnK RimjlfOdU+Ohmm0YEcPfoAvpUyCXOUMOeSEJ2db8KdQMC/LYD5FF/ewIX64hQMaiVpR5 yf6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697457045; x=1698061845; 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=/+oyrZtV1tuM3la1krVprs4qQRZBG6K/5KIJZPiYmoo=; b=swx2BTPzOs+PoSdzGLK1WIowOSeV23KpjG1D+ddhYxmiP4hekBGaPh65XHtka80bIy uaM5gZ3Hck2fcYyq9y+hUo4zOJnJjVlQM2CdvyX4Vi0Qmq2FuGvv3nTqTY4Bb+iHcPGg iXM3UIMerwWZU7UrZvRsf/uDAkR4KpFBK4wAEe463QoHGGCc2790JfOk2EKwROr09VgN Gufd+z7+iYu5G+N0b7VNpM6vx65dv4ue4zWgqDJRZdnkzIajucieVCMyUGn7Zcf7zHvQ TnToleRc3S69ZHVDmHz9GoHKYRq0XPW/WFAKv1XK+G5WXoW3n0/p3qC/RApY/UlVwGEx n+3w== X-Gm-Message-State: AOJu0YwLc1C9WhFrpjw2lolL8n3vrWaVPS3lpyLGbvnCiKhmnZ4bAgPz 79xupDDM3v3Ftwa/Xwa74TBUGeswLgU= X-Google-Smtp-Source: AGHT+IEciIl6eLP6I8wDCR9Vj9tRw3MZ/FxW7MAKPSCRR/F8UwuLcKEIZarCY/uRNsX5XEyUQZ8oaA== X-Received: by 2002:a05:6512:398d:b0:507:8c55:39f9 with SMTP id j13-20020a056512398d00b005078c5539f9mr12246892lfu.49.1697457044808; Mon, 16 Oct 2023 04:50:44 -0700 (PDT) Received: from localhost.localdomain ([2001:2044:c7:5500:e269:21d7:2536:bc4a]) by smtp.gmail.com with ESMTPSA id y10-20020ac2420a000000b004fe2a7a2ee2sm4516529lfh.160.2023.10.16.04.50.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 04:50:44 -0700 (PDT) From: Simon Farre To: gdb-patches@sourceware.org Cc: tromey@adacore.com, Simon Farre Subject: [PATCH v1] [gdb/python]: Add StepEndedEvent (simplifies DAP) Date: Mon, 16 Oct 2023 13:50:26 +0200 Message-ID: <20231016115026.133574-1-simon.farre.cx@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Adds the StepEndedEvent which signals that one of the thread finite state machines finished. Matches the behavior of what is generated by MI; the "end stepping range". This should simplify some of the DAP code, where "expected stop reason" is being tracked. This logic should be handled by the Python interpreter to begin with, instead. --- gdb/NEWS | 3 +++ gdb/doc/python.texi | 3 +++ gdb/python/py-event-types.def | 5 +++++ gdb/python/py-stopevent.c | 17 +++++++++++++++++ 4 files changed, 28 insertions(+) diff --git a/gdb/NEWS b/gdb/NEWS index 81264c0cfb3..b2abaa6a2ce 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -11,6 +11,9 @@ ** New function gdb.notify_mi(NAME, DATA), that emits custom GDB/MI async notification. + ** Added StepEndedEvent which is emitted during stops where it could be determined + that what triggered the stop was that the stepping state machine finished. + *** Changes in GDB 14 * GDB now supports the AArch64 Scalable Matrix Extension 2 (SME2), which diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 546b4d4b962..c6968791eb1 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -3733,6 +3733,9 @@ registry extend @code{gdb.StopEvent}. As a child of thread when @value{GDBN} is running in non-stop mode. Refer to @code{gdb.ThreadEvent} above for more details. +Emits @code{gdb.StepEndedEvent} that signals that this stop event was generated +because one of the step-like commands finished. + Emits @code{gdb.SignalEvent}, which extends @code{gdb.StopEvent}. This event indicates that the inferior or one of its threads has diff --git a/gdb/python/py-event-types.def b/gdb/python/py-event-types.def index c6225115027..36146b181c5 100644 --- a/gdb/python/py-event-types.def +++ b/gdb/python/py-event-types.def @@ -106,6 +106,11 @@ GDB_PY_DEFINE_EVENT_TYPE (signal, "GDB signal event object", stop_event_object_type); +GDB_PY_DEFINE_EVENT_TYPE (step_ended, + "StepEndedEvent", + "GDB step ended event object", + stop_event_object_type); + GDB_PY_DEFINE_EVENT_TYPE (stop, "StopEvent", "GDB stop event object", diff --git a/gdb/python/py-stopevent.c b/gdb/python/py-stopevent.c index 0aa9d5381f8..13e1b12d33a 100644 --- a/gdb/python/py-stopevent.c +++ b/gdb/python/py-stopevent.c @@ -18,6 +18,7 @@ along with this program. If not, see . */ #include "defs.h" +#include "mi/mi-common.h" #include "py-stopevent.h" gdbpy_ref<> @@ -27,6 +28,21 @@ create_stop_event_object (PyTypeObject *py_type) return create_thread_event_object (py_type, thread.get ()); } +/** If thread finite state machine reports that it has finished, inform + the Python-interpreter of this. */ + +static gdbpy_ref<> maybe_create_step_ended () +{ + const auto tp = inferior_thread(); + const auto fsm = tp != nullptr ? tp->thread_fsm() : nullptr; + if (fsm != nullptr && fsm->finished_p () && + fsm->async_reply_reason () == EXEC_ASYNC_END_STEPPING_RANGE) + { + return create_stop_event_object (&step_ended_event_object_type); + } + return nullptr; +} + /* Callback observers when a stop event occurs. This function will create a new Python stop event object. If only a specific thread is stopped the thread object of the event will be set to that thread. Otherwise, if all @@ -86,6 +102,7 @@ emit_stop_event (struct bpstat *bs, enum gdb_signal stop_signal) return -1; } + stop_event_obj = maybe_create_step_ended(); /* If all fails emit an unknown stop event. All event types should be known and this should eventually be unused. */ if (stop_event_obj == NULL) -- 2.41.0