public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/3] gdb: remove unpush_target free function
@ 2021-03-22  3:20 Simon Marchi
  2021-03-22  3:20 ` [PATCH 2/3] gdb: remove push_target free functions Simon Marchi
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Simon Marchi @ 2021-03-22  3:20 UTC (permalink / raw)
  To: gdb-patches

unpush_target unpushes the passed-in target from the current inferior's
target stack.  Calling it is therefore an implicit dependency on the
current global inferior.  Remove that function and make the callers use
the inferior::unpush_target method directly.  This sometimes allows
using the inferior from the context rather than the global current
inferior.

target_unpusher::operator() now needs to be implemented in target.c,
otherwise target.h and inferior.h both need to include each other, and
that wouldn't work.

gdb/ChangeLog:

	* target.h (unpush_target): Remove, update all callers
	to use `inferior::unpush_target` instead.
	(struct target_unpusher) <operator()>: Just declare.
	* target.c (unpush_target): Remove.
	(target_unpusher::operator()): New.

Change-Id: Ia5172dfb3f373e0a75b991885b50322ca2142a8c
---
 gdb/aix-thread.c       |  2 +-
 gdb/bsd-kvm.c          |  2 +-
 gdb/bsd-uthread.c      |  2 +-
 gdb/corelow.c          |  2 +-
 gdb/exec.c             |  2 +-
 gdb/inf-child.c        |  2 +-
 gdb/linux-thread-db.c  |  6 +++---
 gdb/ravenscar-thread.c |  2 +-
 gdb/record-btrace.c    |  2 +-
 gdb/record-full.c      |  2 +-
 gdb/record.c           |  2 +-
 gdb/remote-sim.c       |  4 ++--
 gdb/sol-thread.c       |  4 ++--
 gdb/target.c           | 18 ++++++++----------
 gdb/target.h           |  7 +------
 gdb/tracefile-tfile.c  |  4 ++--
 16 files changed, 28 insertions(+), 35 deletions(-)

diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c
index f4b6c1b06ab6..a479d0150bc2 100644
--- a/gdb/aix-thread.c
+++ b/gdb/aix-thread.c
@@ -993,7 +993,7 @@ pd_disable (void)
   if (pd_active)
     pd_deactivate ();
   pd_able = 0;
-  unpush_target (&aix_thread_ops);
+  current_inferior ()->unpush_target (&aix_thread_ops);
 }
 
 /* new_objfile observer callback.
diff --git a/gdb/bsd-kvm.c b/gdb/bsd-kvm.c
index cd25e19a544e..17db2fe1cd60 100644
--- a/gdb/bsd-kvm.c
+++ b/gdb/bsd-kvm.c
@@ -132,7 +132,7 @@ bsd_kvm_target_open (const char *arg, int from_tty)
     error (("%s"), errbuf);
 
   bsd_kvm_corefile = filename;
-  unpush_target (&bsd_kvm_ops);
+  current_inferior ()->unpush_target (&bsd_kvm_ops);
   core_kd = temp_kd;
   push_target (&bsd_kvm_ops);
 
diff --git a/gdb/bsd-uthread.c b/gdb/bsd-uthread.c
index d7dd0a180142..2ee47bfb5c47 100644
--- a/gdb/bsd-uthread.c
+++ b/gdb/bsd-uthread.c
@@ -259,7 +259,7 @@ bsd_uthread_deactivate (void)
   if (!bsd_uthread_active)
     return;
 
-  unpush_target (&bsd_uthread_ops);
+  current_inferior ()->unpush_target (&bsd_uthread_ops);
 }
 
 static void
diff --git a/gdb/corelow.c b/gdb/corelow.c
index a2d2d20afc62..a4c1f6354c6e 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -580,7 +580,7 @@ core_target::detach (inferior *inf, int from_tty)
   /* Note that 'this' is dangling after this call.  unpush_target
      closes the target, and our close implementation deletes
      'this'.  */
-  unpush_target (this);
+  inf->unpush_target (this);
 
   /* Clear the register cache and the frame cache.  */
   registers_changed ();
diff --git a/gdb/exec.c b/gdb/exec.c
index 544a05873f11..bcc54bd966fe 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -671,7 +671,7 @@ program_space::remove_target_sections (void *owner)
 	    continue;
 
 	  switch_to_inferior_no_thread (inf);
-	  unpush_target (&exec_ops);
+	  inf->unpush_target (&exec_ops);
 	}
     }
 }
diff --git a/gdb/inf-child.c b/gdb/inf-child.c
index 192cfc336913..b8bc2e2598e6 100644
--- a/gdb/inf-child.c
+++ b/gdb/inf-child.c
@@ -207,7 +207,7 @@ void
 inf_child_target::maybe_unpush_target ()
 {
   if (!inf_child_explicitly_opened)
-    unpush_target (this);
+    current_inferior ()->unpush_target (this);
 }
 
 void
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index 4dab64ac3448..3a3d3def6074 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -1364,7 +1364,7 @@ thread_db_target::detach (inferior *inf, int from_tty)
   /* NOTE: From this point on, inferior_ptid is null_ptid.  */
 
   /* Detach the thread_db target from this inferior.  */
-  unpush_target (this);
+  inf->unpush_target (this);
 }
 
 ptid_t
@@ -1398,7 +1398,7 @@ thread_db_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
       /* New image, it may or may not end up using thread_db.  Assume
 	 not unless we find otherwise.  */
       delete_thread_db_info (beneath, ptid.pid ());
-      unpush_target (this);
+      current_inferior ()->unpush_target (this);
 
       return ptid;
     }
@@ -1420,7 +1420,7 @@ thread_db_target::mourn_inferior ()
   target_beneath->mourn_inferior ();
 
   /* Detach the thread_db target from this inferior.  */
-  unpush_target (this);
+  current_inferior ()->unpush_target (this);
 }
 
 struct callback_data
diff --git a/gdb/ravenscar-thread.c b/gdb/ravenscar-thread.c
index 2cc7bbc0ca36..63aa1d1db843 100644
--- a/gdb/ravenscar-thread.c
+++ b/gdb/ravenscar-thread.c
@@ -620,7 +620,7 @@ ravenscar_thread_target::mourn_inferior ()
 {
   m_base_ptid = null_ptid;
   target_ops *beneath = this->beneath ();
-  unpush_target (this);
+  current_inferior ()->unpush_target (this);
   beneath->mourn_inferior ();
 }
 
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index d9cc7a3b6d89..1a0cac2f710e 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -428,7 +428,7 @@ record_btrace_target::disconnect (const char *args,
   struct target_ops *beneath = this->beneath ();
 
   /* Do not stop recording, just clean up GDB side.  */
-  unpush_target (this);
+  current_inferior ()->unpush_target (this);
 
   /* Forward disconnect.  */
   beneath->disconnect (args, from_tty);
diff --git a/gdb/record-full.c b/gdb/record-full.c
index 2373741470c4..59e4410c0085 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -2078,7 +2078,7 @@ record_full_core_target::kill ()
   if (record_debug)
     fprintf_unfiltered (gdb_stdlog, "Process record: record_full_core_kill\n");
 
-  unpush_target (this);
+  current_inferior ()->unpush_target (this);
 }
 
 /* "fetch_registers" method for prec over corefile.  */
diff --git a/gdb/record.c b/gdb/record.c
index cd541b56f438..483b906c2d06 100644
--- a/gdb/record.c
+++ b/gdb/record.c
@@ -166,7 +166,7 @@ record_unpush (struct target_ops *t)
 {
   DEBUG ("unpush %s", t->shortname ());
 
-  unpush_target (t);
+  current_inferior ()->unpush_target (t);
 }
 
 /* See record.h.  */
diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
index d51130562fb1..f72bbd2015e4 100644
--- a/gdb/remote-sim.c
+++ b/gdb/remote-sim.c
@@ -699,7 +699,7 @@ gdbsim_target_open (const char *args, int from_tty)
      operation until after we complete those operations which could
      error out.  */
   if (gdbsim_is_open)
-    unpush_target (&gdbsim_ops);
+    current_inferior ()->unpush_target (&gdbsim_ops);
 
   len = (7 + 1			/* gdbsim */
 	 + strlen (" -E little")
@@ -834,7 +834,7 @@ gdbsim_target::detach (inferior *inf, int from_tty)
   if (remote_debug)
     fprintf_unfiltered (gdb_stdlog, "gdbsim_detach\n");
 
-  unpush_target (this);		/* calls gdbsim_close to do the real work */
+  inf->unpush_target (this);		/* calls gdbsim_close to do the real work */
   if (from_tty)
     printf_filtered ("Ending simulator %s debugging\n", target_shortname);
 }
diff --git a/gdb/sol-thread.c b/gdb/sol-thread.c
index 7b46a5747877..1458185f414f 100644
--- a/gdb/sol-thread.c
+++ b/gdb/sol-thread.c
@@ -387,7 +387,7 @@ sol_thread_target::detach (inferior *inf, int from_tty)
 
   sol_thread_active = 0;
   inferior_ptid = ptid_t (main_ph.ptid.pid ());
-  unpush_target (this);
+  inf->unpush_target (this);
   beneath->detach (inf, from_tty);
 }
 
@@ -681,7 +681,7 @@ sol_thread_target::mourn_inferior ()
 
   sol_thread_active = 0;
 
-  unpush_target (this);
+  current_inferior ()->unpush_target (this);
 
   beneath->mourn_inferior ();
 }
diff --git a/gdb/target.c b/gdb/target.c
index 0889da82ea59..236aded0a2e1 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -160,7 +160,7 @@ set_targetdebug  (const char *args, int from_tty, struct cmd_list_element *c)
   if (targetdebug)
     push_target (the_debug_target);
   else
-    unpush_target (the_debug_target);
+    current_inferior ()->unpush_target (the_debug_target);
 }
 
 static void
@@ -589,14 +589,6 @@ push_target (target_ops_up &&t)
 
 /* See target.h.  */
 
-int
-unpush_target (struct target_ops *t)
-{
-  return current_inferior ()->unpush_target (t);
-}
-
-/* See target.h.  */
-
 bool
 target_stack::unpush (target_ops *t)
 {
@@ -640,7 +632,7 @@ target_stack::unpush (target_ops *t)
 static void
 unpush_target_and_assert (struct target_ops *target)
 {
-  if (!unpush_target (target))
+  if (!current_inferior ()->unpush_target (target))
     {
       fprintf_unfiltered (gdb_stderr,
 			  "pop_all_targets couldn't find target %s\n",
@@ -681,6 +673,12 @@ target_is_pushed (target_ops *t)
   return current_inferior ()->target_is_pushed (t);
 }
 
+void
+target_unpusher::operator() (struct target_ops *ops) const
+{
+  current_inferior ()->unpush_target (ops);
+}
+
 /* Default implementation of to_get_thread_local_address.  */
 
 static void
diff --git a/gdb/target.h b/gdb/target.h
index ee93c5cf3959..3a64094ae5b2 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -2390,16 +2390,11 @@ extern void push_target (struct target_ops *);
 /* An overload that deletes the target on failure.  */
 extern void push_target (target_ops_up &&);
 
-extern int unpush_target (struct target_ops *);
-
 /* A unique_ptr helper to unpush a target.  */
 
 struct target_unpusher
 {
-  void operator() (struct target_ops *ops) const
-  {
-    unpush_target (ops);
-  }
+  void operator() (struct target_ops *ops) const;
 };
 
 /* A unique_ptr that unpushes a target on destruction.  */
diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
index ca6324c03920..ea703643d8f1 100644
--- a/gdb/tracefile-tfile.c
+++ b/gdb/tracefile-tfile.c
@@ -481,7 +481,7 @@ tfile_target_open (const char *arg, int from_tty)
 
   /* Looks semi-reasonable.  Toss the old trace file and work on the new.  */
 
-  unpush_target (&tfile_ops);
+  current_inferior ()->unpush_target (&tfile_ops);
 
   trace_filename = filename.release ();
   trace_fd = scratch_chan;
@@ -551,7 +551,7 @@ tfile_target_open (const char *arg, int from_tty)
   catch (const gdb_exception &ex)
     {
       /* Remove the partially set up target.  */
-      unpush_target (&tfile_ops);
+      current_inferior ()->unpush_target (&tfile_ops);
       throw;
     }
 
-- 
2.30.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-03-23 13:50 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-22  3:20 [PATCH 1/3] gdb: remove unpush_target free function Simon Marchi
2021-03-22  3:20 ` [PATCH 2/3] gdb: remove push_target free functions Simon Marchi
2021-03-22 16:30   ` Aktemur, Tankut Baris
2021-03-22 17:31     ` Simon Marchi
2021-03-22 18:21       ` Simon Marchi
2021-03-23 10:25         ` Aktemur, Tankut Baris
2021-03-23 13:50         ` Simon Marchi
2021-03-22  3:20 ` [PATCH 3/3] gdb: remove target_is_pushed free function Simon Marchi
2021-03-22 16:22 ` [PATCH 1/3] gdb: remove unpush_target " Aktemur, Tankut Baris
2021-03-22 17:25   ` Simon Marchi
2021-03-22 18:11     ` Simon Marchi

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).