From patchwork Thu Apr 25 17:20:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Sternerup X-Patchwork-Id: 88998 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 1FEB93858C5F for ; Thu, 25 Apr 2024 17:21:19 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id A548A3858D20 for ; Thu, 25 Apr 2024 17:20:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A548A3858D20 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 A548A3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::22d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714065639; cv=none; b=LmTbjAnnWc7oyXE2+FhmxR90kLb77zyrvUiwxXM9XUUz/C2YlJpvud5VEeM4ZlCj9wdod73vizXt/dsZ2JXKSrOquWMuWNVa61AxiR7/FkDQjMEuHfw4Zv7FL3Zz8kVfH8h5fkyELHoK/htRExVLX8W87x9ppSOWzgFB4QPg1Ao= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714065639; c=relaxed/simple; bh=rDD1WasyxDlGTJbhL57SemvcGy4OEeTIEwf2BnHXnak=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=b7MO9uUcw+Qb3RJuDweg4JCXHFRJLt96PwADsCINhI+5xIF7JCX2hYjswt9OAG58IgTx7ftDZUQ9ZeklwC7RF+J7WnZIDaNYgZEL7PfrUVCepvy39J9tsVhaocElIqml8S0TW91A9Gwjt7OUsO8nPalddfDwEUUBf4/wzKZE9LQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2da08b06e0dso13387691fa.2 for ; Thu, 25 Apr 2024 10:20:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714065634; x=1714670434; 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=ZVyZp7mClgOuAKXESslLdpofuLq+oKXlkh9651qSs0c=; b=AUqnN7RUAkr3/sGliLkgzSsYM06U8mcw/lzhpKsc+j2k9MQ9PsJt9oUJBbegNuAToi 94+U7f9YAkpXO3JNAnJbnYTthRS74aMF6zwkTQ9LGDnA2bPHPc9IXOFUorzra7ZoGB2x vagf6j8U2I+z35Dpjv5ukY8L3wZvU3WEme+lsFEHSPV4w4NE6Bl7YvV8Xs4B+WiWWKVT aikcskXNHfSV7XlSsFk/H9ZGyv8EuVTeFF/pYk8gwdgsFKdaU37Bqmgyl+4aApoYmkKn AoCcIfl0jPae5564NF6F2/bz23yEDuoMl2voz1d23vtU5rmJ8sk56VB8M6q3f0KnSJ/b jufg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714065634; x=1714670434; 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=ZVyZp7mClgOuAKXESslLdpofuLq+oKXlkh9651qSs0c=; b=uqV3USNeT9XJEdZZMAf4j/XKdRZuM/LgLiECFxb2l9jy+j+6rctY94gQ6gZw+3NavC JZtAfPKJz6c8HubjmUcAgyS1hjpGjDJ+qJWLyIM0WwOu/E2IsKNX/RZSPyA+fZy5a3Tg AJicK47BVQ94k8nt4N7e+uP9zskmhV2JyKOns7twf3orei1rP0tFWnJmGELg9sJ6RtZt T8uxVJeggplCtjbSDejyGg/FpLkYvAL866dPDR4vaCuJtw4LMtmvGgQ36pXsLRMksvFQ fg/9Wke5kOoaXDL46VpfmLed5Jq5r2zNx1hiuZeoLwvvEYO/GFrnsX0MXGhshUHrJK6o UNMQ== X-Gm-Message-State: AOJu0YzDr0YQSCavrvSGkFfC0as3u5EoBSw7lrVMKuz9d9oB+hCDZ+qm ARVsHzXljzYsEUK+/nNB8nBJrXgIAOvfN6QWHBqgdj/QSB54epSXmvIK4w== X-Google-Smtp-Source: AGHT+IFGdtLrEMzNOegayrMhW8rzpnpOipK/rZti0VTNciHJjvsNwl/a2RgQsIyr+skbrf7nsOVezA== X-Received: by 2002:a2e:a4c2:0:b0:2dd:5b94:f7de with SMTP id p2-20020a2ea4c2000000b002dd5b94f7demr8415ljm.23.1714065634088; Thu, 25 Apr 2024 10:20:34 -0700 (PDT) Received: from localhost.localdomain (c-718971d5.882019-0-69706f6e6c79.bbcust.telenor.se. [213.113.137.113]) by smtp.gmail.com with ESMTPSA id z34-20020a2ebe22000000b002dd7feaa75dsm1321121ljq.124.2024.04.25.10.20.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 10:20:33 -0700 (PDT) From: Johan Sternerup To: gdb-patches@sourceware.org Cc: Johan Sternerup Subject: [PATCH] Handle DAP "stepOut" request in outermost frame Date: Thu, 25 Apr 2024 19:20:19 +0200 Message-Id: <20240425172019.863412-1-johan.sternerup@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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 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 Previously a "stepOut" request when in the outermost frame would result in a sucessful response even though gdb internally would reject the associated "finish" request, which means no stoppedEvent would ever be sent back to the client. Thus the client would believe the inferior was still running and as a consequence reject subsequent "next" and "stepIn" requests from the user. The solution here is to make the same check that is made in 'infcmd.c/finish_command()' to make sure we're not in the outermost frame, but now we do it _before_ actually running the "finish" command so that we can send an error response immediately. --- gdb/python/lib/gdb/dap/next.py | 10 ++++++---- gdb/testsuite/gdb.dap/step-out.exp | 11 +++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/gdb/python/lib/gdb/dap/next.py b/gdb/python/lib/gdb/dap/next.py index 1dc1d6dd74d..05a9946b752 100644 --- a/gdb/python/lib/gdb/dap/next.py +++ b/gdb/python/lib/gdb/dap/next.py @@ -17,7 +17,7 @@ import gdb from .events import exec_and_expect_stop from .server import capability, request, send_gdb, send_gdb_with_response -from .startup import in_gdb_thread +from .startup import DAPException, in_gdb_thread from .state import set_thread @@ -73,10 +73,12 @@ def step_in( exec_and_expect_stop(cmd) -@request("stepOut", response=False) +@request("stepOut", on_dap_thread=True) def step_out(*, threadId: int, singleThread: bool = False, **args): - _handle_thread_step(threadId, singleThread, True) - exec_and_expect_stop("finish") + if not gdb.selected_frame().older(): + raise DAPException("\"finish\" not meaningful in the outermost frame.") + send_gdb_with_response(lambda: _handle_thread_step(threadId, singleThread)) + send_gdb(lambda: exec_and_expect_stop("finish")) # This is a server-side request because it is funny: it wants to diff --git a/gdb/testsuite/gdb.dap/step-out.exp b/gdb/testsuite/gdb.dap/step-out.exp index 757f4ebdaca..207eb73e191 100644 --- a/gdb/testsuite/gdb.dap/step-out.exp +++ b/gdb/testsuite/gdb.dap/step-out.exp @@ -79,4 +79,15 @@ gdb_assert {[dict get $varlist variablesReference] > 0} \ gdb_assert {[dict get $varlist name] == "(return)"} \ "variable is return value" +set response_and_events [dap_request_and_response stepOut {o threadId [i 1]}] +set response [lindex $response_and_events 0] +if {[dict get $response success] == "true"} { + fail "stepOut from outermost frame should not succeed" +} else { + pass "stepOut from outermost frame failed like it should" +} + +dap_check_request_and_response "still stopped and may request backtrace" \ + stackTrace {o threadId [i 1]} + dap_shutdown