]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: introduce a new overload of target_can_async_p
authorAndrew Burgess <aburgess@redhat.com>
Wed, 24 Nov 2021 11:15:55 +0000 (11:15 +0000)
committerAndrew Burgess <aburgess@redhat.com>
Thu, 25 Nov 2021 09:54:58 +0000 (09:54 +0000)
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.  I
then make use of the new overload where appropriate.

There should be no user visible changes after this commit.

gdb/infcmd.c
gdb/mi/mi-main.c
gdb/target.c
gdb/target.h

index 6bbd45618eb2764514daa3719217bfb1d41762ad..984ce4e042ba0d782979a6181a307b02aef3f392 100644 (file)
@@ -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)
index e28fae0cc6cf87ef1fc2efe464085af8061f6b89..311697b2d58ebbfb0d7dc3e7f88939c23e58b87f 100644 (file)
@@ -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);
index 8fe27c775ea74beb036305666375ad6f9dc35f25..970e2a784b59dc87039d4a53f59d97582a72b4a2 100644 (file)
@@ -391,7 +391,15 @@ target_can_lock_scheduler ()
 bool
 target_can_async_p ()
 {
-  return current_inferior ()->top_target ()->can_async_p ();
+  return target_can_async_p (current_inferior ()->top_target ());
+}
+
+/* See target.h.  */
+
+bool
+target_can_async_p (struct target_ops *target)
+{
+  return target->can_async_p ();
 }
 
 /* See target.h.  */
@@ -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);
index 4dc17fd4806d6d2948a2a187a23577db1dc6fc32..e709b7d7cfdcf3517537fd6ca633bb7373241380 100644 (file)
@@ -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 ();