From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) by sourceware.org (Postfix) with ESMTPS id D12433858425 for ; Fri, 17 Nov 2023 17:49:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D12433858425 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 D12433858425 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::132 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700243351; cv=none; b=XcKZW6ITRfllPphHIiuzG/YrfFlzj1qxIt3J7CnJ0zw7LjSflQ47/x5bea+ExKr9i6ul7SFWkdIDLYDjLu0Wu7+VJrYXGowfFzcMW6oWmyZRvnjEQdNz3UobmYppe/tKfRDmJEMhDijj7oyXzWNfovc0MNWmByR9JU9Fo1P7yC8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700243351; c=relaxed/simple; bh=dnSJD2vBHpsytaV2JCVlq37ejDfv7zZt7fda6b26+X0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=XN72Ufl+cfIDD3skcKPh1F9SW4h6y6DU1yD7CAff9C6E9co8fvy2lGN+em3iJ4k5rA8+4wJC/YMBlS9DTAkozdfXrxR57T40Fm1ccAafya5KQXhqJ8RKjVKidBkLpYaOXpv8Fw70kQExqnIjFjqz6XURtuA06V5zHzMDOexWJbU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x132.google.com with SMTP id e9e14a558f8ab-359343e399fso7428895ab.0 for ; Fri, 17 Nov 2023 09:49:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1700243349; x=1700848149; 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=jhXDF03NiYSox83Xb12ENqMcRWtk91kSiv9EfmTOrfs=; b=eZC6tIj1Jmf6hYAd3mJMiBf6VOPmoDYeuyPgohQbb5PxFigq6B/sJckRX1llRwJeJ1 TJAttUAY8oYH8VV4CSmZYs4iaB9XRM7Hm2pvcw/zH+9q9f/5k4olchfG1Gh4xWOiRhVd p8PeO/RSyjWS/o43N8enEMMh1/X0Jkcz7sh9bIuSW3znMeLfdJxoQ/bmfzUr7NDVNFtn M1guw7Br3olec+qmBjuxFCuITnZWhcXfXFoa28nwII7fInpm33TVDMKakNRKNHrHh4LC tAx8ku105yi3TTnIr9GCzVQPhW/KOXZk14E4cKJSR7Q4oxUZNfPw35cw2UHbDxxlMyfR xTng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700243349; x=1700848149; 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=jhXDF03NiYSox83Xb12ENqMcRWtk91kSiv9EfmTOrfs=; b=C4AkN/1KtoUR2RbSYCL2g8X1czAVp2RjhkBgWWDJRtRI0igPjkbidNFxKsuBjq8SDL LNgAP4QvS93ORanNuB9Iu6DmgAIjGAojnNqc34yq1yvfpDRCz0gzvIS9URNhqZFT/Lm7 TA5CFcYgGmZ46CZ1ejpUc6wohpalGlcemdgV3Swi2XQShKwhUPfpz867WpeblVH+IHBL CGRcfJzh5AswEFYoVfQPeF8LPBHWzqYxDzoxONEoxmxvSGYGmj7Kl12G0RFxrQg/0g4f SO4iVNqq7mGQHBXyysYDySplZU9XTSJ6Bg7aPh/F0Te0mpgNgiO4nZRuRtM0kFBzUYO6 D1Sg== X-Gm-Message-State: AOJu0Yyjazy8cu9tLqRJJtoHRK7JYU3Uc6uuXsT5+0WK+aFq3wMZANqJ eIhgKw9UeZ0CmESuiY7SA28No65LfvJxiGpAyGBWKA== X-Google-Smtp-Source: AGHT+IEIQIA3Cr5bu8Ni9Lg3nIj8XY0QFhhT6C2uVoePSLW4btfJAUelDxr1+Ya3H544zwZ/B3RUrg== X-Received: by 2002:a92:7606:0:b0:357:478f:a744 with SMTP id r6-20020a927606000000b00357478fa744mr162363ilc.10.1700243348795; Fri, 17 Nov 2023 09:49:08 -0800 (PST) Received: from localhost.localdomain (97-122-77-73.hlrn.qwest.net. [97.122.77.73]) by smtp.gmail.com with ESMTPSA id 8-20020a056e020ca800b0034aa175c9c3sm590947ilg.87.2023.11.17.09.49.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 09:49:08 -0800 (PST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix bug in DAP handling of 'pause' requests Date: Fri, 17 Nov 2023 10:49:01 -0700 Message-ID: <20231117174901.4111817-1-tromey@adacore.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.7 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: While working on cancellation, I noticed that a DAP 'pause' request would set the "do not emit the continue" flag. This meant that a subsequent request that should provoke a 'continue' event would instead suppress the event. I then tried writing a more obvious test case for this, involving an inferior call -- and discovered that gdb.events.cont does not fire for an inferior call. This patch installs a new event listener for gdb.events.inferior_call and arranges for this to emit continue and stop events when appropriate. It also fixes the original bug, by adding a check to exec_and_expect_stop. --- gdb/python/lib/gdb/dap/events.py | 26 +++++++++++++++++-- gdb/testsuite/gdb.dap/pause.c | 44 ++++++++++++++++++++++++++++++++ gdb/testsuite/gdb.dap/pause.exp | 30 +++++++++++++++++++++- 3 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 gdb/testsuite/gdb.dap/pause.c diff --git a/gdb/python/lib/gdb/dap/events.py b/gdb/python/lib/gdb/dap/events.py index bfc3f9ee1dc..663b67ea24e 100644 --- a/gdb/python/lib/gdb/dap/events.py +++ b/gdb/python/lib/gdb/dap/events.py @@ -128,8 +128,9 @@ def exec_and_expect_stop(cmd, reason): """Indicate that a stop is expected, then execute CMD""" global _expected_stop _expected_stop = reason - global _suppress_cont - _suppress_cont = True + if reason != StopKinds.PAUSE: + global _suppress_cont + _suppress_cont = True # FIXME if the call fails should we clear _suppress_cont? exec_and_log(cmd) @@ -156,6 +157,26 @@ def _on_stop(event): send_event("stopped", obj) +# This keeps a bit of state between the start of an inferior call and +# the end. If the inferior was already running when the call started +# (as can happen if a breakpoint condition calls a function), then we +# do not want to emit 'continued' or 'stop' events for the call. Note +# that, for some reason, gdb.events.cont does not fire for an infcall. +_infcall_was_running = False + + +@in_gdb_thread +def _on_inferior_call(event): + global _infcall_was_running + if isinstance(event, gdb.InferiorCallPreEvent): + _infcall_was_running = inferior_running + if not _infcall_was_running: + _cont(None) + else: + if not _infcall_was_running: + _on_stop(None) + + gdb.events.stop.connect(_on_stop) gdb.events.exited.connect(_on_exit) gdb.events.new_thread.connect(_new_thread) @@ -163,3 +184,4 @@ gdb.events.thread_exited.connect(_thread_exited) gdb.events.cont.connect(_cont) gdb.events.new_objfile.connect(_new_objfile) gdb.events.free_objfile.connect(_objfile_removed) +gdb.events.inferior_call.connect(_on_inferior_call) diff --git a/gdb/testsuite/gdb.dap/pause.c b/gdb/testsuite/gdb.dap/pause.c new file mode 100644 index 00000000000..2395ca64dd3 --- /dev/null +++ b/gdb/testsuite/gdb.dap/pause.c @@ -0,0 +1,44 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2011-2023 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +int +do_nothing () +{ + return 91; +} + +int +return_false () +{ + return 0; +} + +void +sleep_a_bit () +{ + sleep (1); /* STOP */ +} + +int +main () +{ + while (1) + sleep_a_bit (); + return 0; +} diff --git a/gdb/testsuite/gdb.dap/pause.exp b/gdb/testsuite/gdb.dap/pause.exp index 558ede982ee..30ce6095225 100644 --- a/gdb/testsuite/gdb.dap/pause.exp +++ b/gdb/testsuite/gdb.dap/pause.exp @@ -19,7 +19,7 @@ require allow_dap_tests load_lib dap-support.exp -standard_testfile attach.c +standard_testfile if {[build_executable ${testfile}.exp $testfile $srcfile] == -1} { return @@ -29,6 +29,18 @@ if {[dap_launch $testfile] == ""} { return } +# Set a conditional breakpoint that will never fire. This is done to +# test the state-tracking in events -- an inferior call from a +# breakpoint condition should not cause any sort of stop or continue +# events. +set line [gdb_get_line_number "STOP"] +dap_check_request_and_response "set conditional breakpoint" \ + setBreakpoints \ + [format {o source [o path [%s]] \ + breakpoints [a [o line [i %d] \ + condition [s "return_false()"]]]} \ + [list s $srcfile] $line] + dap_check_request_and_response "start inferior" configurationDone dap_wait_for_event_and_check "inferior started" thread "body reason" started @@ -45,4 +57,20 @@ dap_check_request_and_response pause pause \ dap_wait_for_event_and_check "stopped by pause" stopped \ "body reason" pause +set result [dap_request_and_response evaluate {o expression [s do_nothing()]}] +gdb_assert {[dict get [lindex $result 0] body result] == 91} \ + "check result of evaluation" + +set seen fail +foreach event [lindex $result 1] { + if {[dict get $event type] != "event"} { + continue + } + if {[dict get $event event] == "continued"} { + set seen pass + break + } +} +gdb_assert {$seen == "pass"} "continue event from inferior call" + dap_shutdown -- 2.41.0