]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: remove push_target free functions
authorSimon Marchi <simon.marchi@polymtl.ca>
Tue, 23 Mar 2021 13:50:35 +0000 (09:50 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Tue, 23 Mar 2021 13:50:35 +0000 (09:50 -0400)
Same as the previous patch, but for the push_target functions.

The implementation of the move variant is moved to a new overload of
inferior::push_target.

gdb/ChangeLog:

* target.h (push_target): Remove, update callers to use
inferior::push_target.
* target.c (push_target): Remove.
* inferior.h (class inferior) <push_target>: New overload.

Change-Id: I5a95496666278b8f3965e5e8aecb76f54a97c185

30 files changed:
gdb/ChangeLog
gdb/aix-thread.c
gdb/bsd-kvm.c
gdb/bsd-uthread.c
gdb/corelow.c
gdb/darwin-nat.c
gdb/exec.c
gdb/gnu-nat.c
gdb/go32-nat.c
gdb/inf-child.c
gdb/inf-ptrace.c
gdb/inferior.c
gdb/inferior.h
gdb/infrun.c
gdb/linux-thread-db.c
gdb/nto-procfs.c
gdb/procfs.c
gdb/ravenscar-thread.c
gdb/record-btrace.c
gdb/record-full.c
gdb/regcache.c
gdb/remote-sim.c
gdb/remote.c
gdb/scoped-mock-context.h
gdb/sol-thread.c
gdb/target.c
gdb/target.h
gdb/tracectf.c
gdb/tracefile-tfile.c
gdb/windows-nat.c

index 7396237d90f285f43b19a0f71c98074d1b62a8a4..274e157905d71fcf06f46e26cbaaf00b3642046b 100644 (file)
@@ -1,3 +1,10 @@
+2021-03-23  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * target.h (push_target): Remove, update callers to use
+       inferior::push_target.
+       * target.c (push_target): Remove.
+       * inferior.h (class inferior) <push_target>: New overload.
+
 2021-03-23  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * target.h (unpush_target): Remove, update all callers
index a479d0150bc209865d7dbb1dce39d2cd3259bf03..fc34210cf9e2e77ad81f35f28a539eba7ae456b2 100644 (file)
@@ -974,7 +974,7 @@ pd_enable (void)
     return;
 
   /* Prepare for thread debugging.  */
-  push_target (&aix_thread_ops);
+  current_inferior ()->push_target (&aix_thread_ops);
   pd_able = 1;
 
   /* If we're debugging a core file or an attached inferior, the
index 17db2fe1cd60dbdc4a4d2676ea784d382ba504e4..89da40afcb78f213a1a9ab62d9bb9ef99ec6d73f 100644 (file)
@@ -134,7 +134,7 @@ bsd_kvm_target_open (const char *arg, int from_tty)
   bsd_kvm_corefile = filename;
   current_inferior ()->unpush_target (&bsd_kvm_ops);
   core_kd = temp_kd;
-  push_target (&bsd_kvm_ops);
+  current_inferior ()->push_target (&bsd_kvm_ops);
 
   thread_info *thr = add_thread_silent (&bsd_kvm_ops, bsd_kvm_ptid);
   switch_to_thread (thr);
index 2ee47bfb5c47335d7246182ba06e79648ceecfa1..3cb8f64c89a7243d916d7acf4a854195af1a6619 100644 (file)
@@ -231,7 +231,7 @@ bsd_uthread_activate (struct objfile *objfile)
   bsd_uthread_thread_ctx_offset =
     bsd_uthread_lookup_offset ("_thread_ctx_offset", objfile);
 
-  push_target (&bsd_uthread_ops);
+  current_inferior ()->push_target (&bsd_uthread_ops);
   bsd_uthread_active = 1;
   return 1;
 }
index a4c1f6354c6e427ca449e9e3f6fc7e5c09e45bd0..a1943ab2ea6dc03f576d654bbc732c9acbabff8d 100644 (file)
@@ -458,7 +458,7 @@ core_target_open (const char *arg, int from_tty)
   if (!current_program_space->exec_bfd ())
     set_gdbarch_from_file (core_bfd);
 
-  push_target (std::move (target_holder));
+  current_inferior ()->push_target (std::move (target_holder));
 
   switch_to_no_thread ();
 
index ca95d7b6d38505604c949f56a912388305e8250e..f8e4443ff408f14388ecf8674b420e385864511f 100644 (file)
@@ -1659,7 +1659,7 @@ darwin_attach_pid (struct inferior *inf)
 
   target_ops *darwin_ops = get_native_target ();
   if (!target_is_pushed (darwin_ops))
-    push_target (darwin_ops);
+    inf->push_target (darwin_ops);
 }
 
 /* Get the thread_info object corresponding to this darwin_thread_info.  */
index bcc54bd966fe15d6a1e028f5e3fbc241a94f0aed..b737bcf6e0f3c25462233b39cf50be0d24e4b5aa 100644 (file)
@@ -616,7 +616,7 @@ program_space::add_target_sections (void *owner,
            continue;
 
          switch_to_inferior_no_thread (inf);
-         push_target (&exec_ops);
+         inf->push_target (&exec_ops);
        }
     }
 }
@@ -682,7 +682,7 @@ void
 exec_on_vfork ()
 {
   if (!current_program_space->target_sections ().empty ())
-    push_target (&exec_ops);
+    current_inferior ()->push_target (&exec_ops);
 }
 
 \f
index 409d141909b3adbfab7e174904a2bf3e104c75ae..9ea4c408934054d230fb001e68d28e17d3031bb1 100644 (file)
@@ -2114,7 +2114,7 @@ gnu_nat_target::create_inferior (const char *exec_file,
   inf_debug (inf, "creating inferior");
 
   if (!target_is_pushed (this))
-    push_target (this);
+    current_inferior ()->push_target (this);
 
   pid = fork_inferior (exec_file, allargs, env, gnu_ptrace_me,
                       NULL, NULL, NULL, NULL);
@@ -2190,9 +2190,9 @@ gnu_nat_target::attach (const char *args, int from_tty)
 
   inf_attach (inf, pid);
 
-  push_target (this);
-
   inferior = current_inferior ();
+  inferior->push_target (this);
+
   inferior_appeared (inferior, pid);
   inferior->attach_flag = 1;
 
index b18a62e9490deb974fa24e096345b983fca5ceaf..79c31fcd98771d89051f495be7b704d74644dd0c 100644 (file)
@@ -757,7 +757,7 @@ go32_nat_target::create_inferior (const char *exec_file,
   inferior_appeared (inf, SOME_PID);
 
   if (!target_is_pushed (this))
-    push_target (this);
+    inf->push_target (this);
 
   thread_info *thr = add_thread_silent (ptid_t (SOME_PID));
   switch_to_thread (thr);
index b8bc2e2598e649ad3e53371d5e9bb470232e19fb..0e68a40d7c04a91fd7d35c674bbb0770fef65a6c 100644 (file)
@@ -166,7 +166,7 @@ inf_child_open_target (const char *arg, int from_tty)
   gdb_assert (dynamic_cast<inf_child_target *> (target) != NULL);
 
   target_preopen (from_tty);
-  push_target (target);
+  current_inferior ()->push_target (target);
   inf_child_explicitly_opened = 1;
   if (from_tty)
     printf_filtered ("Done.  Use the \"run\" command to start a process.\n");
index 7ca02dfd87643efa227b52c8c070a03b4abba3f5..e630ba447f40ae7b983293ffcc63b6e463227a18 100644 (file)
@@ -82,7 +82,7 @@ inf_ptrace_target::create_inferior (const char *exec_file,
   if (! ops_already_pushed)
     {
       /* Clear possible core file with its process_stratum.  */
-      push_target (this);
+      current_inferior ()->push_target (this);
       unpusher.reset (this);
     }
 
@@ -139,12 +139,14 @@ inf_ptrace_target::attach (const char *args, int from_tty)
   if (pid == getpid ())                /* Trying to masturbate?  */
     error (_("I refuse to debug myself!"));
 
+  inf = current_inferior ();
+
   target_unpush_up unpusher;
   if (! ops_already_pushed)
     {
       /* target_pid_to_str already uses the target.  Also clear possible core
         file with its process_stratum.  */
-      push_target (this);
+      inf->push_target (this);
       unpusher.reset (this);
     }
 
@@ -169,7 +171,6 @@ inf_ptrace_target::attach (const char *args, int from_tty)
   error (_("This system does not support attaching to a process"));
 #endif
 
-  inf = current_inferior ();
   inferior_appeared (inf, pid);
   inf->attach_flag = 1;
 
index 49f869a4c783a93472b2c2bec082c0a2316dae8b..69baee34ce9d25dd26eda5fc78feadc853708e67 100644 (file)
@@ -771,7 +771,7 @@ switch_to_inferior_and_push_target (inferior *new_inf,
   /* Reuse the target for new inferior.  */
   if (!no_connection && proc_target != NULL)
     {
-      push_target (proc_target);
+      new_inf->push_target (proc_target);
       if (proc_target->connection_string () != NULL)
        printf_filtered (_("Added inferior %d on connection %d (%s %s)\n"),
                         new_inf->num,
index b8d5ff94fc56742996149f17fdecaeb7d48e5cc4..66fc180ce53034f05204c2d0bdac8bbb8d47f741 100644 (file)
@@ -352,6 +352,13 @@ public:
   void push_target (struct target_ops *t)
   { m_target_stack.push (t); }
 
+  /* An overload that deletes the target on failure.  */
+  void push_target (target_ops_up &&t)
+  {
+    m_target_stack.push (t.get ());
+    t.release ();
+  }
+
   /* Unpush T from this inferior's target stack.  */
   int unpush_target (struct target_ops *t)
   { return m_target_stack.unpush (t); }
index 3b65a6de9fe21159b32ba0455c0146ed8196ac99..50340e6edad4c30542c176e43c3589a6d658684d 100644 (file)
@@ -477,7 +477,7 @@ holding the child stopped.  Try \"set detach-on-fork\" or \
          set_current_inferior (child_inf);
          switch_to_no_thread ();
          child_inf->symfile_flags = SYMFILE_NO_READ;
-         push_target (parent_inf->process_target ());
+         child_inf->push_target (parent_inf->process_target ());
          thread_info *child_thr
            = add_thread_silent (child_inf->process_target (), child_ptid);
 
@@ -627,7 +627,7 @@ holding the child stopped.  Try \"set detach-on-fork\" or \
           informing the solib layer about this new process.  */
 
        set_current_inferior (child_inf);
-       push_target (target);
+       child_inf->push_target (target);
       }
 
       thread_info *child_thr = add_thread_silent (target, child_ptid);
@@ -1183,7 +1183,7 @@ follow_exec (ptid_t ptid, const char *exec_file_target)
 
       inferior *org_inferior = current_inferior ();
       switch_to_inferior_no_thread (inf);
-      push_target (org_inferior->process_target ());
+      inf->push_target (org_inferior->process_target ());
       thread_info *thr = add_thread (inf->process_target (), ptid);
       switch_to_thread (thr);
     }
index 3a3d3def6074eb0559cbbbd93ede95b3587e016e..de8687e99c730f9643d1b99ba351b75eaa57a830 100644 (file)
@@ -944,7 +944,7 @@ try_thread_db_load_1 (struct thread_db_info *info)
 
   /* The thread library was detected.  Activate the thread_db target
      for this process.  */
-  push_target (&the_thread_db_target);
+  current_inferior ()->push_target (&the_thread_db_target);
   return true;
 }
 
index 021230af9c6243aa388e60ba734e36fcc32e641d..b74392fef3201e252869db19e4a3a14eb86db5e2 100644 (file)
@@ -718,7 +718,7 @@ nto_procfs_target::attach (const char *args, int from_tty)
   inf->attach_flag = 1;
 
   if (!target_is_pushed (ops))
-    push_target (ops);
+    inf->push_target (ops);
 
   update_thread_list ();
 
@@ -1319,7 +1319,7 @@ nto_procfs_target::create_inferior (const char *exec_file,
         errn, safe_strerror(errn) ); */
     }
   if (!target_is_pushed (ops))
-    push_target (ops);
+    inf->push_target (ops);
   target_terminal::init ();
 
   if (current_program_space->exec_bfd () != NULL
index cab29c3cbbcb57ef577684b8f14d625e45a2487b..b37680923cd84e0298ab1809747e4bf08535e79f 100644 (file)
@@ -1771,7 +1771,7 @@ procfs_target::attach (const char *args, int from_tty)
   target_unpush_up unpusher;
   if (!target_is_pushed (this))
     {
-      push_target (this);
+      current_inferior ()->push_target (this);
       unpusher.reset (this);
     }
 
@@ -2863,7 +2863,7 @@ procfs_target::create_inferior (const char *exec_file,
     }
 
   if (!target_is_pushed (this))
-    push_target (this);
+    current_inferior ()->push_target (this);
 
   pid = fork_inferior (exec_file, allargs, env, procfs_set_exec_trap,
                       NULL, procfs_pre_trace, shell_file, NULL);
index 63aa1d1db843e8d64948c2869b8de959041e0e5b..1398d1b7c9e6138262f75f6e271a6a4d68a1bfb4 100644 (file)
@@ -674,7 +674,7 @@ ravenscar_inferior_created (inferior *inf)
     }
 
   ravenscar_thread_target *rtarget = new ravenscar_thread_target ();
-  push_target (target_ops_up (rtarget));
+  inf->push_target (target_ops_up (rtarget));
   thread_info *thr = rtarget->add_active_thread ();
   if (thr != nullptr)
     switch_to_thread (thr);
index 1a0cac2f710e543039819af019453b04de5304bd..b7b3c91f85dbb11c38a6fae9d93b1585daa60643 100644 (file)
@@ -337,7 +337,7 @@ record_btrace_push_target (void)
 
   record_btrace_auto_enable ();
 
-  push_target (&record_btrace_ops);
+  current_inferior ()->push_target (&record_btrace_ops);
 
   record_btrace_async_inferior_event_handler
     = create_async_event_handler (record_btrace_handle_async_inferior_event,
index 59e4410c0085182391977b6c94bb9a74fdc9d24f..8310b7b4c25663521cdb8429a63ad055bbf52d1c 100644 (file)
@@ -924,7 +924,7 @@ record_full_core_open_1 (const char *name, int from_tty)
 
   record_full_core_sections = build_section_table (core_bfd);
 
-  push_target (&record_full_core_ops);
+  current_inferior ()->push_target (&record_full_core_ops);
   record_full_restore ();
 }
 
@@ -947,7 +947,7 @@ record_full_open_1 (const char *name, int from_tty)
     error (_("Process record: the current architecture doesn't support "
             "record function."));
 
-  push_target (&record_full_ops);
+  current_inferior ()->push_target (&record_full_ops);
 }
 
 static void record_full_init_record_breakpoints (void);
index 27c0ae5ae2398bd4b1bbf85a5214c80baee271aa..a419a21f30a06454e706b883cd0ebbeef6bfb372 100644 (file)
@@ -1925,7 +1925,7 @@ cooked_write_test (struct gdbarch *gdbarch)
 
   /* Push the process_stratum target so we can mock accessing
      registers.  */
-  push_target (&mock_target);
+  current_inferior ()->push_target (&mock_target);
 
   /* Pop it again on exit (return/exception).  */
   struct on_exit
index f72bbd2015e407987cb43c60c55b10e8a443ec49..1746b626fa11d51019d342a5fcefa9d351298183 100644 (file)
@@ -763,7 +763,7 @@ gdbsim_target_open (const char *args, int from_tty)
 
   sim_data->gdbsim_desc = gdbsim_desc;
 
-  push_target (&gdbsim_ops);
+  current_inferior ()->push_target (&gdbsim_ops);
   printf_filtered ("Connected to the simulator.\n");
 
   /* There's nothing running after "target sim" or "load"; not until
index ae15f416153f91747166201972ef35fc6db744ed..a7f35396045b8c2edfb90eb315cde275de0ab3b8 100644 (file)
@@ -2474,7 +2474,7 @@ remote_target::remote_add_inferior (bool fake_pid_p, int pid, int attached,
          inf = add_inferior_with_spaces ();
        }
       switch_to_inferior_no_thread (inf);
-      push_target (this);
+      inf->push_target (this);
       inferior_appeared (inf, pid);
     }
 
@@ -5673,7 +5673,7 @@ remote_target::open_1 (const char *name, int from_tty, int extended_p)
     }
 
   /* Switch to using the remote target now.  */
-  push_target (std::move (target_holder));
+  current_inferior ()->push_target (std::move (target_holder));
 
   /* Register extra event sources in the event loop.  */
   rs->remote_async_inferior_event_token
index 8332e462326b7ee9731c269fa742ab245c97a70c..8d295ba1bbe6c42c50711156d033f582ea738a6f 100644 (file)
@@ -64,7 +64,7 @@ struct scoped_mock_context
     /* Push the process_stratum target so we can mock accessing
        registers.  */
     gdb_assert (mock_target.stratum () == process_stratum);
-    push_target (&mock_target);
+    mock_inferior.push_target (&mock_target);
 
     /* Switch to the mock thread.  */
     switch_to_thread (&mock_thread);
index 1458185f414fafcbbacec0858f186036cb45ab2d..825f69131fc46e4e6d4b240e811b3fca50add169 100644 (file)
@@ -641,7 +641,7 @@ check_for_thread_db (void)
       printf_unfiltered (_("[Thread debugging using libthread_db enabled]\n"));
 
       /* The thread library was detected.  Activate the sol_thread target.  */
-      push_target (&sol_thread_ops);
+      current_inferior ()->push_target (&sol_thread_ops);
       sol_thread_active = 1;
 
       main_ph.ptid = inferior_ptid; /* Save for xfer_memory.  */
index 236aded0a2e175269248ce61ce9f04e8e330dcac..fe9731221efd7048183d61c785de9b332ad6126d 100644 (file)
@@ -158,7 +158,7 @@ static void
 set_targetdebug  (const char *args, int from_tty, struct cmd_list_element *c)
 {
   if (targetdebug)
-    push_target (the_debug_target);
+    current_inferior ()->push_target (the_debug_target);
   else
     current_inferior ()->unpush_target (the_debug_target);
 }
@@ -572,23 +572,6 @@ target_stack::push (target_ops *t)
 
 /* See target.h.  */
 
-void
-push_target (struct target_ops *t)
-{
-  current_inferior ()->push_target (t);
-}
-
-/* See target.h.  */
-
-void
-push_target (target_ops_up &&t)
-{
-  current_inferior ()->push_target (t.get ());
-  t.release ();
-}
-
-/* See target.h.  */
-
 bool
 target_stack::unpush (target_ops *t)
 {
index 3a64094ae5b2394350da0283ea5e795949ac4937..1830d3a8106f7c58d252029af75e554170aa918c 100644 (file)
@@ -2385,11 +2385,6 @@ extern void add_target (const target_info &info,
 extern void add_deprecated_target_alias (const target_info &info,
                                         const char *alias);
 
-extern void push_target (struct target_ops *);
-
-/* An overload that deletes the target on failure.  */
-extern void push_target (target_ops_up &&);
-
 /* A unique_ptr helper to unpush a target.  */
 
 struct target_unpusher
index 38c327dd1df0f9aa32b54b4b16dd36c510413dfb..4a245ee11a5affcf3ae26982eb1a2d20efef88b7 100644 (file)
@@ -1165,7 +1165,7 @@ ctf_target_open (const char *dirname, int from_tty)
   gdb_assert (start_pos->type == BT_SEEK_RESTORE);
 
   trace_dirname = xstrdup (dirname);
-  push_target (&ctf_ops);
+  current_inferior ()->push_target (&ctf_ops);
 
   inferior_appeared (current_inferior (), CTF_PID);
 
index ea703643d8f1b81223ba37110fdee9e0a3ebf1cd..d82cac8d9ddd04fdb3b20d2f5904c21944fbc7df 100644 (file)
@@ -498,7 +498,7 @@ tfile_target_open (const char *arg, int from_tty)
        && (startswith (header + 1, "TRACE0\n"))))
     error (_("File is not a valid trace file."));
 
-  push_target (&tfile_ops);
+  current_inferior ()->push_target (&tfile_ops);
 
   trace_regblock_size = 0;
   ts = current_trace_status ();
index c8275fc5420479988fd85d14de6ad571841ffb6a..51662896d691c65d6ec5e18d2f0004bd5a2b7c71 100644 (file)
@@ -2027,8 +2027,9 @@ windows_nat_target::do_initial_windows_stuff (DWORD pid, bool attaching)
 #endif
   current_event.dwProcessId = pid;
   memset (&current_event, 0, sizeof (current_event));
+  inf = current_inferior ();
   if (!target_is_pushed (this))
-    push_target (this);
+    inf->push_target (this);
   disable_breakpoints_in_shlibs ();
   windows_clear_solib ();
   clear_proceed_status (0);
@@ -2049,7 +2050,6 @@ windows_nat_target::do_initial_windows_stuff (DWORD pid, bool attaching)
       windows_set_segment_register_p (i386_windows_segment_register_p);
     }
 
-  inf = current_inferior ();
   inferior_appeared (inf, pid);
   inf->attach_flag = attaching;