From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id BA3993858409 for ; Tue, 23 Nov 2021 14:08:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BA3993858409 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-288-8ipilD01OT6Z95WaIEhW8w-1; Tue, 23 Nov 2021 09:08:33 -0500 X-MC-Unique: 8ipilD01OT6Z95WaIEhW8w-1 Received: by mail-wm1-f70.google.com with SMTP id j193-20020a1c23ca000000b003306ae8bfb7so8502026wmj.7 for ; Tue, 23 Nov 2021 06:08:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=G3Ot+y9MpQBRSVvsnbw5wBXRvlUVZ0aMwNxWaUbXqWM=; b=GhNTm71/5rH0DlbsrTAtxlti97psFxJ9jSZ9gyzoFSOaNM3n8mj/0DNOHzoIlibIcd stWNVn65KTERLU5fPmebATJBR5OkdsglHE5/ObfyXqNPiuvYilCbOK5Il2Tksv7HuPBr wQxvgoVpyI3pgswhTWyyZ52DCNBxSz40oDmlNqQoczhtB29vkIfuxiJWFwhbXX/cnvYC a+7AjudyUiji1pk2Es1AKBZW3LzqJYrghDB8Separpn1/4ckTzxJpPed+1HZnT8KF82V r9+vcKsN+eGv2zPz1q20BOv0+GPkQWMThkPOuGDRFXPjZVx9tWJ2ObGpvjOHOHNamwCr T1kw== X-Gm-Message-State: AOAM532tcngjd8gmX/qn8ihyuBjhesCQGTNJ8eQ1RiiAj+X8t1xJhEta wueOAsoOjbifURk0HmUYXKV4Xilbf9MRvyipxZ3o1liqhDgO8fh6OdyuysarHqYjNHJDAyT9F4L R8K5PZXVyz3zAXyjUcUEIJCUj6wlCN/RXMb+bs/xHsmHsuPmDbZzxyMYvXtRrskhXW4W4iChvlw == X-Received: by 2002:adf:f207:: with SMTP id p7mr5150732wro.173.1637676511562; Tue, 23 Nov 2021 06:08:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJx1sxJjVoth7/kYQhR+QXQiITXJIqoQc9gxLcwesPtg69bv7NNfcXpDIYmtc9/3UpsYKhfrWA== X-Received: by 2002:adf:f207:: with SMTP id p7mr5150672wro.173.1637676511105; Tue, 23 Nov 2021 06:08:31 -0800 (PST) Received: from localhost (host86-166-129-255.range86-166.btcentralplus.com. [86.166.129.255]) by smtp.gmail.com with ESMTPSA id 8sm1174514wmg.24.2021.11.23.06.08.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 06:08:30 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 1/4] gdb: add asserts in target.c for target_async_permitted Date: Tue, 23 Nov 2021 14:08:20 +0000 Message-Id: <0e15e93ed36baa678af2d11771fd6bf7f5227897.1637676250.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Nov 2021 14:08:38 -0000 The target_async_permitted flag allows a user to override whether a target can act in async mode or not. Ideally we would check this flag in target_can_async_p and target_is_async_p, however, there are a few places in GDB where we call the can_async_p and is_async_p methods directly without calling through the target_* wrapper. As a result each target must check the target_async_permitted flag in their own method implementations. However, as the target_can_async_p and target_is_async_p functions are also called in some places, what we can do is add an assert in these functions that ensures targets are checking target_async_permitted correctly. So, the rule is: in target_can_async_p and target_is_async_p, if the global target_async_permitted is false, then the result of calling the target_ops method (::can_async_p or ::is_async_p) should also be false. Right now, I believe that only the linux_nat_target and the remote_target support async mode, and these targets do, correctly check target_async_permitted. But if, in future, additional targets add support for async mode, then these asserts should ensure that the targets are checking target_async_permitted correctly. Further, the target_async method is used to enable or disable async mode for a target. My claim here is that we should only try to enable async mode for targets if target_async_permitted is true, and if the target supports async mode. I've added an assertion to this effect in the target_async function. There should be no user visible changes after this commit. --- gdb/target.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gdb/target.c b/gdb/target.c index 8fe27c775ea..f8e56cceb08 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -391,7 +391,9 @@ target_can_lock_scheduler () bool target_can_async_p () { - return current_inferior ()->top_target ()->can_async_p (); + bool result = current_inferior ()->top_target ()->can_async_p (); + gdb_assert (target_async_permitted || !result); + return result; } /* See target.h. */ @@ -399,7 +401,9 @@ target_can_async_p () bool target_is_async_p () { - return current_inferior ()->top_target ()->is_async_p (); + bool result = current_inferior ()->top_target ()->is_async_p (); + gdb_assert (target_async_permitted || !result); + return result; } exec_direction_kind @@ -4328,6 +4332,9 @@ maintenance_print_target_stack (const char *cmd, int from_tty) void target_async (int enable) { + /* If we are trying to enable async mode then it must be the case that + async mode is both allowed, and the target supports async mode. */ + gdb_assert (!enable || (target_async_permitted && target_can_async_p ())); infrun_async (enable); current_inferior ()->top_target ()->async (enable); } -- 2.25.4