From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH 1/4] gdb: add asserts in target.c for target_async_permitted
Date: Tue, 23 Nov 2021 14:08:20 +0000 [thread overview]
Message-ID: <0e15e93ed36baa678af2d11771fd6bf7f5227897.1637676250.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1637676250.git.aburgess@redhat.com>
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
next prev parent reply other threads:[~2021-11-23 14:08 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-23 14:08 [PATCH 0/4] Improve 'maint set target-async off' for remote targets Andrew Burgess
2021-11-23 14:08 ` Andrew Burgess [this message]
2021-11-23 21:31 ` [PATCH 1/4] gdb: add asserts in target.c for target_async_permitted Simon Marchi
2021-11-23 14:08 ` [PATCH 2/4] gdb/remote: merge ::is_async_p and ::can_async_p methods Andrew Burgess
2021-11-23 21:33 ` Simon Marchi
2021-11-24 10:14 ` Andrew Burgess
2021-11-23 14:08 ` [PATCH 3/4] gdb: add assert in remote_target::wait relating to async being off Andrew Burgess
2021-11-23 21:50 ` Simon Marchi
2021-11-23 14:08 ` [PATCH 4/4] gdb/remote: some fixes for 'maint set target-async off' Andrew Burgess
2021-11-23 22:03 ` Simon Marchi
2021-11-23 16:39 ` [PATCH 0/4] Improve 'maint set target-async off' for remote targets John Baldwin
2021-11-24 12:22 ` [PATCHv2 0/6] " Andrew Burgess
2021-11-24 12:22 ` [PATCHv2 1/6] gdb: introduce a new overload of target_can_async_p Andrew Burgess
2021-11-24 12:22 ` [PATCHv2 2/6] gdb: hoist target_async_permitted checks into target.c Andrew Burgess
2021-11-24 21:17 ` Simon Marchi
2021-11-24 12:22 ` [PATCHv2 3/6] gdb: add asserts in target.c for target_async_permitted Andrew Burgess
2021-11-24 21:21 ` Simon Marchi
2021-11-24 12:22 ` [PATCHv2 4/6] gdb: simplify remote_target::is_async_p Andrew Burgess
2021-11-24 12:22 ` [PATCHv2 5/6] gdb: add assert in remote_target::wait relating to async being off Andrew Burgess
2021-11-24 21:23 ` Simon Marchi
2021-11-25 10:04 ` Andrew Burgess
2021-11-25 11:36 ` Tom de Vries
2021-11-25 13:46 ` Andrew Burgess
2021-11-25 14:17 ` Tom de Vries
2021-11-24 12:22 ` [PATCHv2 6/6] gdb/remote: some fixes for 'maint set target-async off' Andrew Burgess
2021-12-01 10:40 ` [PATCHv3 0/2] Improve 'maint set target-async off' for remote targets Andrew Burgess
2021-12-01 10:40 ` [PATCHv3 1/2] gdb/remote: some fixes for 'maint set target-async off' Andrew Burgess
2021-12-16 21:15 ` Pedro Alves
2021-12-17 13:35 ` Andrew Burgess
2021-12-17 14:05 ` Pedro Alves
2021-12-18 10:21 ` Andrew Burgess
2021-12-01 10:40 ` [PATCHv3 2/2] gdb: add assert in remote_target::wait relating to async being off Andrew Burgess
2021-12-16 21:16 ` Pedro Alves
2021-12-18 10:21 ` Andrew Burgess
2021-12-13 11:41 ` PING: [PATCHv3 0/2] Improve 'maint set target-async off' for remote targets Andrew Burgess
2021-12-13 17:20 ` John Baldwin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0e15e93ed36baa678af2d11771fd6bf7f5227897.1637676250.git.aburgess@redhat.com \
--to=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).