public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCHv2 1/6] gdb: introduce a new overload of target_can_async_p
Date: Wed, 24 Nov 2021 12:22:04 +0000	[thread overview]
Message-ID: <b2de6384eefae71964ec501e09453fa349b25ebc.1637756330.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1637756330.git.aburgess@redhat.com>

There are a few places where we call the target_ops::can_async_p
member function directly, instead of using the target_can_async_p
wrapper.

In some of these places this is because we need to ask before the
target has been pushed, and in another location (in target.c) it seems
unnecessary to go through the wrapper when we are already in target.c
code.

However, in the next commit I'd like to hoist some common checks out
of target specific code into target.c.  To achieve this, in this
commit I introduce a new overload of target_can_async_p which takes a
target_ops pointer, and calls the ::can_async_p method directly.

This commit adds the new overload, and has everyone call though it.

There should be no user visible changes after this commit.
---
 gdb/infcmd.c     |  2 +-
 gdb/mi/mi-main.c |  4 ++--
 gdb/target.c     | 10 +++++++++-
 gdb/target.h     |  4 ++++
 4 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 6bbd45618eb..984ce4e042b 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -336,7 +336,7 @@ prepare_execution_command (struct target_ops *target, int background)
 {
   /* If we get a request for running in the bg but the target
      doesn't support it, error out.  */
-  if (background && !target->can_async_p ())
+  if (background && !target_can_async_p (target))
     error (_("Asynchronous execution not supported on this target."));
 
   if (!background)
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index e28fae0cc6c..311697b2d58 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -408,7 +408,7 @@ run_one_inferior (inferior *inf, bool start_p)
 {
   const char *run_cmd = start_p ? "start" : "run";
   struct target_ops *run_target = find_run_target ();
-  int async_p = mi_async && run_target->can_async_p ();
+  int async_p = mi_async && target_can_async_p (run_target);
 
   if (inf->pid != 0)
     {
@@ -473,7 +473,7 @@ mi_cmd_exec_run (const char *command, char **argv, int argc)
     {
       const char *run_cmd = start_p ? "start" : "run";
       struct target_ops *run_target = find_run_target ();
-      int async_p = mi_async && run_target->can_async_p ();
+      int async_p = mi_async && target_can_async_p (run_target);
 
       mi_execute_cli_command (run_cmd, async_p,
 			      async_p ? "&" : NULL);
diff --git a/gdb/target.c b/gdb/target.c
index 8fe27c775ea..c5276ae0fe7 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -396,6 +396,14 @@ target_can_async_p ()
 
 /* See target.h.  */
 
+bool
+target_can_async_p (struct target_ops *target)
+{
+  return target->can_async_p ();
+}
+
+/* See target.h.  */
+
 bool
 target_is_async_p ()
 {
@@ -2602,7 +2610,7 @@ target_wait (ptid_t ptid, struct target_waitstatus *status,
 
   gdb_assert (!proc_target->commit_resumed_state);
 
-  if (!target->can_async_p ())
+  if (!target_can_async_p (target))
     gdb_assert ((options & TARGET_WNOHANG) == 0);
 
   return target->wait (ptid, status, options);
diff --git a/gdb/target.h b/gdb/target.h
index 4dc17fd4806..e709b7d7cfd 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -1886,6 +1886,10 @@ extern bool target_async_permitted;
 /* Can the target support asynchronous execution?  */
 extern bool target_can_async_p ();
 
+/* An overload of the above that can be called when the target is not yet
+   pushed, this calls TARGET::can_async_p directly.  */
+extern bool target_can_async_p (struct target_ops *target);
+
 /* Is the target in asynchronous execution mode?  */
 extern bool target_is_async_p ();
 
-- 
2.25.4


  reply	other threads:[~2021-11-24 12:22 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 ` [PATCH 1/4] gdb: add asserts in target.c for target_async_permitted Andrew Burgess
2021-11-23 21:31   ` 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   ` Andrew Burgess [this message]
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=b2de6384eefae71964ec501e09453fa349b25ebc.1637756330.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).