gdb: remove push_target free functions

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
This commit is contained in:
Simon Marchi 2021-03-23 09:50:35 -04:00
parent fadf6add30
commit 02980c5645
30 changed files with 54 additions and 61 deletions

View 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

View 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

View 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);

View 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;
}

View 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 ();

View 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. */

View 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);
}

View 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;

View 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);

View 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");

View 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;

View 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,

View 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); }

View 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);
}

View 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;
}

View 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

View 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);

View 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);

View 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,

View 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);

View 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

View 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

View 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

View 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);

View 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. */

View 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)
{

View 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

View 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);

View 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 ();

View 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;