From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by sourceware.org (Postfix) with ESMTPS id 0EFD73857714 for ; Wed, 24 May 2023 16:37:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0EFD73857714 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-76c5c806fc5so32534639f.1 for ; Wed, 24 May 2023 09:37:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1684946251; x=1687538251; h=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=C+pRqRmr8LkaDcwu5fBccACxv36XHJktyvbzMxUuxb8=; b=YOb6zka216Z5OKSv03+fanvQ5SL45PWZtrTOWuZTujvG4giRpgDqA/wJ2oLAza/PDT I3p8+mXayWuEPx8H9H9t3E5tHcArTM+dXo/6pgMmN3cD4LPo2dMyZ9UJke/8FYmSHyk1 G0ugrwhBZrI7AkRKbJ6T6rH4On4TE0L0lB7zaPZ0CP2t8PeZ0FAxeHhqEajpdkVV1sAB 0Q90TvE44m1OsX3cEhD0i+OKDih7BdFOOB4W/qOh2zVABaOer/PcIWiTaf3ix0DSqhY5 BlrdhmpN58f0kBz9ktCHqMOMrG37Q73FZ0fR7wtpdc7e66o+W9jzHg2TnFhMJ9iXS4jU 5iLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946251; x=1687538251; h=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=C+pRqRmr8LkaDcwu5fBccACxv36XHJktyvbzMxUuxb8=; b=WjXG3wzWmvjlr8FxfmCfuwtEpzrM3U6ooGy52BCnWzoIoJoaWBx84oEAL6B60zWzG5 iErbNVEvFo9P5IFqnpN6ZXvFqu65cFRT7BlhPrsZw784/gDJgASSlzWa+4yMYdDHM4Jl XvMRumHLW+NCDm5KvWw4S6p6NNycyFvKWJCXX8meaaGPNCkyxY5a8MJlMZ3+LH3Jmd4d iN2YoEstkTatTRZ1mIBEQfeVWdnR9v4RkKmJe7m3sTlMc+Hb8QfpoyW20lHKNCFahFrp LkCEq7n0NoTM+gfm2/ViKArmg3OE1D4K9Tc43DO4tSomYP2wskgsSmtM3xTP3AhHjntS CNfw== X-Gm-Message-State: AC+VfDwB1o3s0kqbDRMZdJ1xjc8Rp5Txtwqt+0/FPcn8Bb+HgSYvSvGD SS5/iG1iFABIAFmztsQDPodktVDRR6L1MfUWiMxufg== X-Google-Smtp-Source: ACHHUZ5x+f5yE8T9QQYauEXNm7VYtlNtKnTJR4lBDSz5UlrBTJDLMuibtSllPronY34LBOaIMJb3ug== X-Received: by 2002:a6b:e80f:0:b0:76c:615c:7c1 with SMTP id f15-20020a6be80f000000b0076c615c07c1mr11635072ioh.16.1684946251356; Wed, 24 May 2023 09:37:31 -0700 (PDT) Received: from localhost.localdomain (71-211-130-244.hlrn.qwest.net. [71.211.130.244]) by smtp.gmail.com with ESMTPSA id o22-20020a6bcf16000000b0076c81bf2731sm3397266ioa.20.2023.05.24.09.37.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 09:37:30 -0700 (PDT) From: Tom Tromey Date: Wed, 24 May 2023 10:37:03 -0600 Subject: [PATCH 12/25] Add singleThread support to some DAP requests MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230427-ada-catch-exception-v1-12-947caa9905e3@adacore.com> References: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> In-Reply-To: <20230427-ada-catch-exception-v1-0-947caa9905e3@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,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 List-Id: A few DAP requests support a "singleThread" parameter, which is somewhat similar to scheduler-locking. This patch implements support for this. --- gdb/python/lib/gdb/dap/next.py | 45 ++++++++++++++++++++++--------- gdb/testsuite/gdb.dap/basic-dap.exp | 9 ++++--- gdb/testsuite/gdb.dap/catch-exception.exp | 3 ++- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/gdb/python/lib/gdb/dap/next.py b/gdb/python/lib/gdb/dap/next.py index 232b1529fe5..290b9b855ba 100644 --- a/gdb/python/lib/gdb/dap/next.py +++ b/gdb/python/lib/gdb/dap/next.py @@ -13,21 +13,40 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import gdb + from .events import StopKinds, ExecutionInvoker from .server import capability, request -from .startup import send_gdb +from .startup import in_gdb_thread, send_gdb, send_gdb_with_response from .state import set_thread -# Helper function to set the current thread. -def _handle_thread_step(threadId): +# Helper function to set the current thread and the scheduler-locking +# mode. Returns True if scheduler-locking was successfully set to +# 'on', False in all other cases, including error. +@in_gdb_thread +def _handle_thread_step(thread_id, single_thread): # Ensure we're going to step the correct thread. - send_gdb(lambda: set_thread(threadId)) + set_thread(thread_id) + if single_thread: + result = True + arg = "on" + else: + result = False + arg = "off" + try: + # This can fail, depending on the target, so catch the error + # and report to our caller. We can't use exec_and_log because + # that does not propagate exceptions. + gdb.execute("set scheduler-locking " + arg, from_tty=True, to_string=True) + except gdb.error: + result = False + return result @request("next") -def next(*, threadId, granularity="statement", **args): - _handle_thread_step(threadId) +def next(*, threadId, singleThread=False, granularity="statement", **args): + send_gdb(lambda: _handle_thread_step(threadId, singleThread)) cmd = "next" if granularity == "instruction": cmd += "i" @@ -35,9 +54,10 @@ def next(*, threadId, granularity="statement", **args): @capability("supportsSteppingGranularity") +@capability("supportsSingleThreadExecutionRequests") @request("stepIn") -def stepIn(*, threadId, granularity="statement", **args): - _handle_thread_step(threadId) +def stepIn(*, threadId, singleThread=False, granularity="statement", **args): + send_gdb(lambda: _handle_thread_step(threadId, singleThread)) cmd = "step" if granularity == "instruction": cmd += "i" @@ -45,12 +65,13 @@ def stepIn(*, threadId, granularity="statement", **args): @request("stepOut") -def step_out(*, threadId): - _handle_thread_step(threadId) +def step_out(*, threadId, singleThread=False): + send_gdb(lambda: _handle_thread_step(threadId, singleThread)) send_gdb(ExecutionInvoker("finish", StopKinds.STEP)) @request("continue") -def continue_request(**args): +def continue_request(*, threadId, singleThread=False, **args): + locked = send_gdb_with_response(lambda: _handle_thread_step(threadId, singleThread)) send_gdb(ExecutionInvoker("continue", None)) - return {"allThreadsContinued": True} + return {"allThreadsContinued": not locked} diff --git a/gdb/testsuite/gdb.dap/basic-dap.exp b/gdb/testsuite/gdb.dap/basic-dap.exp index d4dbdac70ff..ce739875404 100644 --- a/gdb/testsuite/gdb.dap/basic-dap.exp +++ b/gdb/testsuite/gdb.dap/basic-dap.exp @@ -136,15 +136,18 @@ set obj [dap_check_request_and_response "evaluate global second time" \ dap_match_values "global value after step" [lindex $obj 0] \ "body result" 24 -dap_check_request_and_response "continue to address" continue +dap_check_request_and_response "continue to address" continue \ + {o threadId [i 1]} dap_wait_for_event_and_check "stopped at address breakpoint" stopped \ "body reason" breakpoint \ "body hitBreakpointIds" $insn_bpno -dap_check_request_and_response "continue to line" continue +dap_check_request_and_response "continue to line" continue \ + {o threadId [i 1]} dap_wait_for_event_and_check "stopped at line breakpoint" stopped \ "body reason" breakpoint \ - "body hitBreakpointIds" $line_bpno + "body hitBreakpointIds" $line_bpno \ + "body allThreadsStopped" true dap_check_request_and_response "return from function" stepOut \ {o threadId [i 1]} diff --git a/gdb/testsuite/gdb.dap/catch-exception.exp b/gdb/testsuite/gdb.dap/catch-exception.exp index 6bfeb3ed87e..7f2e750b32e 100644 --- a/gdb/testsuite/gdb.dap/catch-exception.exp +++ b/gdb/testsuite/gdb.dap/catch-exception.exp @@ -57,7 +57,8 @@ dap_wait_for_event_and_check "stopped at first raise" stopped \ "body reason" breakpoint \ "body hitBreakpointIds" 2 -dap_check_request_and_response "continue to assert" continue +dap_check_request_and_response "continue to assert" continue \ + {o threadId [i 1]} dap_wait_for_event_and_check "stopped at assert" stopped \ "body reason" breakpoint \ "body hitBreakpointIds" 1 -- 2.40.0