gnu-nat: Move local functions inside gnu_nat_target class

This allows to have the process_stratum_target object at hand for future use in
the gdb API, and only use gnu_target from external calls.

gdb/Changelog:

	* gnu-nat.h (inf_validate_procs, inf_suspend, inf_set_traced,
	steal_exc_port, proc_get_state, inf_clear_wait, inf_cleanup,
	inf_startup, inf_update_suspends, inf_set_pid, inf_steal_exc_ports,
	inf_validate_procinfo, inf_validate_task_sc, inf_restore_exc_ports,
	inf_set_threads_resume_sc, inf_set_threads_resume_sc_for_signal_thread,
	inf_resume, inf_set_step_thread, inf_detach, inf_attach, inf_signal,
	inf_continue, make_proc, proc_abort, _proc_free, proc_update_sc,
	proc_get_exception_port, proc_set_exception_port, _proc_get_exc_port,
	proc_steal_exc_port, proc_restore_exc_port, proc_trace): Move functions
	to gnu_nat_target class.
	* gnu-nat.c: Likewise.
	(inf_update_procs, S_proc_wait_reply, set_task_pause_cmd,
	set_task_exc_port_cmd, set_signals_cmd, set_thread_pause_cmd,
	set_thread_exc_port_cmd): Call inf_validate_procs through gnu_target
	object.
	(gnu_nat_target::create_inferior, gnu_nat_target::detach): Pass `this'
	instead of `gnu_target'.
This commit is contained in:
Samuel Thibault 2020-05-31 07:42:10 +00:00
parent 40dba20562
commit 14a8ad62e6
3 changed files with 115 additions and 88 deletions

View File

@ -1,3 +1,23 @@
2020-05-30 Samuel Thibault <samuel.thibault@ens-lyon.org>
* gnu-nat.h (inf_validate_procs, inf_suspend, inf_set_traced,
steal_exc_port, proc_get_state, inf_clear_wait, inf_cleanup,
inf_startup, inf_update_suspends, inf_set_pid, inf_steal_exc_ports,
inf_validate_procinfo, inf_validate_task_sc, inf_restore_exc_ports,
inf_set_threads_resume_sc, inf_set_threads_resume_sc_for_signal_thread,
inf_resume, inf_set_step_thread, inf_detach, inf_attach, inf_signal,
inf_continue, make_proc, proc_abort, _proc_free, proc_update_sc,
proc_get_exception_port, proc_set_exception_port, _proc_get_exc_port,
proc_steal_exc_port, proc_restore_exc_port, proc_trace): Move functions
to gnu_nat_target class.
* gnu-nat.c: Likewise.
(inf_update_procs, S_proc_wait_reply, set_task_pause_cmd,
set_task_exc_port_cmd, set_signals_cmd, set_thread_pause_cmd,
set_thread_exc_port_cmd): Call inf_validate_procs through gnu_target
object.
(gnu_nat_target::create_inferior, gnu_nat_target::detach): Pass `this'
instead of `gnu_target'.
2020-05-30 Samuel Thibault <samuel.thibault@ens-lyon.org>
* i386-gnu-tdep.c: Include "gdbcore.h"

View File

@ -101,42 +101,12 @@ bool gnu_debug_flag = false;
/* Forward decls */
static struct inf *make_inf ();
void inf_clear_wait (struct inf *inf);
void inf_cleanup (struct inf *inf);
void inf_startup (struct inf *inf, int pid);
int inf_update_suspends (struct inf *inf);
void inf_set_pid (struct inf *inf, pid_t pid);
void inf_validate_procs (struct inf *inf);
void inf_steal_exc_ports (struct inf *inf);
void inf_restore_exc_ports (struct inf *inf);
void inf_set_threads_resume_sc (struct inf *inf,
struct proc *run_thread,
int run_others);
int inf_set_threads_resume_sc_for_signal_thread (struct inf *inf);
void inf_suspend (struct inf *inf);
void inf_resume (struct inf *inf);
void inf_set_step_thread (struct inf *inf, struct proc *proc);
void inf_detach (struct inf *inf);
void inf_attach (struct inf *inf, int pid);
void inf_signal (struct inf *inf, enum gdb_signal sig);
void inf_continue (struct inf *inf);
#define inf_debug(_inf, msg, args...) \
do { struct inf *__inf = (_inf); \
debug ("{inf %d %s}: " msg, __inf->pid, \
host_address_to_string (__inf) , ##args); } while (0)
void proc_abort (struct proc *proc, int force);
struct proc *make_proc (struct inf *inf, mach_port_t port, int tid);
struct proc *_proc_free (struct proc *proc);
int proc_update_sc (struct proc *proc);
kern_return_t proc_get_exception_port (struct proc *proc, mach_port_t * port);
kern_return_t proc_set_exception_port (struct proc *proc, mach_port_t port);
static mach_port_t _proc_get_exc_port (struct proc *proc);
void proc_steal_exc_port (struct proc *proc, mach_port_t exc_port);
void proc_restore_exc_port (struct proc *proc);
int proc_trace (struct proc *proc, int set);
/* Evaluate RPC_EXPR in a scope with the variables MSGPORT and REFPORT bound
to INF's msg port and task port respectively. If it has no msg port,
EIEIO is returned. INF must refer to a running process! */
@ -265,7 +235,7 @@ __proc_pid (struct proc *proc)
/* Update PROC's real suspend count to match it's desired one. Returns true
if we think PROC is now in a runnable state. */
int
proc_update_sc (struct proc *proc)
gnu_nat_target::proc_update_sc (struct proc *proc)
{
int running;
int err = 0;
@ -331,7 +301,7 @@ proc_update_sc (struct proc *proc)
In particular, a thread is precious if it's running (in which case forcing
it includes suspending it first), or if it has an exception pending. */
void
proc_abort (struct proc *proc, int force)
gnu_nat_target::proc_abort (struct proc *proc, int force)
{
gdb_assert (proc_is_thread (proc));
@ -368,7 +338,7 @@ proc_abort (struct proc *proc, int force)
that the thread is stopped and aborted first, and sets the state_changed
field in PROC to true. */
thread_state_t
proc_get_state (struct proc *proc, int will_modify)
gnu_nat_target::proc_get_state (struct proc *proc, int will_modify)
{
int was_aborted = proc->aborted;
@ -405,7 +375,7 @@ proc_get_state (struct proc *proc, int will_modify)
/* Set PORT to PROC's exception port. */
kern_return_t
proc_get_exception_port (struct proc * proc, mach_port_t * port)
gnu_nat_target::proc_get_exception_port (struct proc * proc, mach_port_t * port)
{
if (proc_is_task (proc))
return task_get_exception_port (proc->port, port);
@ -415,7 +385,7 @@ proc_get_exception_port (struct proc * proc, mach_port_t * port)
/* Set PROC's exception port to PORT. */
kern_return_t
proc_set_exception_port (struct proc * proc, mach_port_t port)
gnu_nat_target::proc_set_exception_port (struct proc * proc, mach_port_t port)
{
proc_debug (proc, "setting exception port: %lu", port);
if (proc_is_task (proc))
@ -425,8 +395,8 @@ proc_set_exception_port (struct proc * proc, mach_port_t port)
}
/* Get PROC's exception port, cleaning up a bit if proc has died. */
static mach_port_t
_proc_get_exc_port (struct proc *proc)
mach_port_t
gnu_nat_target::_proc_get_exc_port (struct proc *proc)
{
mach_port_t exc_port;
kern_return_t err = proc_get_exception_port (proc, &exc_port);
@ -449,7 +419,7 @@ _proc_get_exc_port (struct proc *proc)
been done. Stash away any existing exception port so we can
restore it later. */
void
proc_steal_exc_port (struct proc *proc, mach_port_t exc_port)
gnu_nat_target::proc_steal_exc_port (struct proc *proc, mach_port_t exc_port)
{
mach_port_t cur_exc_port = _proc_get_exc_port (proc);
@ -492,7 +462,7 @@ proc_steal_exc_port (struct proc *proc, mach_port_t exc_port)
found there at the time, unless *our* exception port has since been
overwritten, in which case who knows what's going on. */
void
proc_restore_exc_port (struct proc *proc)
gnu_nat_target::proc_restore_exc_port (struct proc *proc)
{
mach_port_t cur_exc_port = _proc_get_exc_port (proc);
@ -522,7 +492,7 @@ proc_restore_exc_port (struct proc *proc)
/* Turns hardware tracing in PROC on or off when SET is true or false,
respectively. Returns true on success. */
int
proc_trace (struct proc *proc, int set)
gnu_nat_target::proc_trace (struct proc *proc, int set)
{
thread_state_t state = proc_get_state (proc, 1);
@ -552,7 +522,7 @@ static int next_thread_id = 1;
/* Returns a new proc structure with the given fields. Also adds a
notification for PORT becoming dead to be sent to INF's notify port. */
struct proc *
make_proc (struct inf *inf, mach_port_t port, int tid)
gnu_nat_target::make_proc (struct inf *inf, mach_port_t port, int tid)
{
kern_return_t err;
mach_port_t prev_port = MACH_PORT_NULL;
@ -616,7 +586,7 @@ make_proc (struct inf *inf, mach_port_t port, int tid)
/* Frees PROC and any resources it uses, and returns the value of PROC's
next field. */
struct proc *
_proc_free (struct proc *proc)
gnu_nat_target::_proc_free (struct proc *proc)
{
struct inf *inf = proc->inf;
struct proc *next = proc->next;
@ -685,7 +655,7 @@ make_inf (void)
/* Clear INF's target wait status. */
void
inf_clear_wait (struct inf *inf)
gnu_nat_target::inf_clear_wait (struct inf *inf)
{
inf_debug (inf, "clearing wait");
inf->wait.status.kind = TARGET_WAITKIND_SPURIOUS;
@ -705,7 +675,7 @@ inf_clear_wait (struct inf *inf)
void
inf_cleanup (struct inf *inf)
gnu_nat_target::inf_cleanup (struct inf *inf)
{
inf_debug (inf, "cleanup");
@ -728,7 +698,7 @@ inf_cleanup (struct inf *inf)
}
void
inf_startup (struct inf *inf, int pid)
gnu_nat_target::inf_startup (struct inf *inf, int pid)
{
kern_return_t err;
@ -751,7 +721,7 @@ inf_startup (struct inf *inf, int pid)
/* Close current process, if any, and attach INF to process PORT. */
void
inf_set_pid (struct inf *inf, pid_t pid)
gnu_nat_target::inf_set_pid (struct inf *inf, pid_t pid)
{
task_t task_port;
struct proc *task = inf->task;
@ -803,8 +773,8 @@ inf_set_pid (struct inf *inf, pid_t pid)
proc server state. Note that the traced field is only updated from
the proc server state if we do not have a message port. If we do
have a message port we'd better look at the tracemask itself. */
static void
inf_validate_procinfo (struct inf *inf)
void
gnu_nat_target::inf_validate_procinfo (struct inf *inf)
{
char *noise;
mach_msg_type_number_t noise_len = 0;
@ -830,8 +800,8 @@ inf_validate_procinfo (struct inf *inf)
/* Validates INF's task suspend count. If it's higher than we expect,
verify with the user before `stealing' the extra count. */
static void
inf_validate_task_sc (struct inf *inf)
void
gnu_nat_target::inf_validate_task_sc (struct inf *inf)
{
char *noise;
mach_msg_type_number_t noise_len = 0;
@ -882,8 +852,8 @@ inf_validate_task_sc (struct inf *inf)
is. If INF is running, the resume_sc count of INF's threads will
be modified, and the signal thread will briefly be run to change
the trace state. */
static void
inf_set_traced (struct inf *inf, int on)
void
gnu_nat_target::inf_set_traced (struct inf *inf, int on)
{
if (on == inf->traced)
return;
@ -919,7 +889,7 @@ inf_set_traced (struct inf *inf, int on)
counts in the safe order. Returns true if at least one thread is
thought to be running. */
int
inf_update_suspends (struct inf *inf)
gnu_nat_target::inf_update_suspends (struct inf *inf)
{
struct proc *task = inf->task;
@ -1010,7 +980,7 @@ inf_threads (struct inf *inf, inf_threads_ftype *f, void *arg)
/* Make INF's list of threads be consistent with reality of TASK. */
void
inf_validate_procs (struct inf *inf)
gnu_nat_target::inf_validate_procs (struct inf *inf)
{
thread_array_t threads;
mach_msg_type_number_t num_threads, i;
@ -1109,12 +1079,12 @@ inf_validate_procs (struct inf *inf)
if (inferior_ptid == ptid_t (inf->pid))
/* This is the first time we're hearing about thread
ids, after a fork-child. */
thread_change_ptid (gnu_target, inferior_ptid, ptid);
thread_change_ptid (this, inferior_ptid, ptid);
else if (inf->pending_execs != 0)
/* This is a shell thread. */
add_thread_silent (gnu_target, ptid);
add_thread_silent (this, ptid);
else
add_thread (gnu_target, ptid);
add_thread (this, ptid);
}
}
@ -1131,7 +1101,7 @@ inf_update_procs (struct inf *inf)
if (!inf->task)
return 0;
if (!inf->threads_up_to_date)
inf_validate_procs (inf);
gnu_target->inf_validate_procs (inf);
return !!inf->task;
}
@ -1139,8 +1109,8 @@ inf_update_procs (struct inf *inf)
and others are set to their run_sc if RUN_OTHERS is true, and otherwise
their pause_sc. */
void
inf_set_threads_resume_sc (struct inf *inf,
struct proc *run_thread, int run_others)
gnu_nat_target::inf_set_threads_resume_sc (struct inf *inf,
struct proc *run_thread, int run_others)
{
struct proc *thread;
@ -1158,7 +1128,7 @@ inf_set_threads_resume_sc (struct inf *inf,
/* Cause INF to continue execution immediately; individual threads may still
be suspended (but their suspend counts will be updated). */
void
inf_resume (struct inf *inf)
gnu_nat_target::inf_resume (struct inf *inf)
{
struct proc *thread;
@ -1183,7 +1153,7 @@ inf_resume (struct inf *inf)
/* Cause INF to stop execution immediately; individual threads may still
be running. */
void
inf_suspend (struct inf *inf)
gnu_nat_target::inf_suspend (struct inf *inf)
{
struct proc *thread;
@ -1203,7 +1173,7 @@ inf_suspend (struct inf *inf)
function changes it to be PROC, changing any old step_thread to be
a normal one. A PROC of 0 clears any existing value. */
void
inf_set_step_thread (struct inf *inf, struct proc *thread)
gnu_nat_target::inf_set_step_thread (struct inf *inf, struct proc *thread)
{
gdb_assert (!thread || proc_is_thread (thread));
@ -1229,7 +1199,7 @@ inf_set_step_thread (struct inf *inf, struct proc *thread)
(plus whatever other thread are set to always run). Returns true if we
did so, or false if we can't find a signal thread. */
int
inf_set_threads_resume_sc_for_signal_thread (struct inf *inf)
gnu_nat_target::inf_set_threads_resume_sc_for_signal_thread (struct inf *inf)
{
if (inf->signal_thread)
{
@ -1251,7 +1221,7 @@ inf_update_signal_thread (struct inf *inf)
/* Detachs from INF's inferior task, letting it run once again... */
void
inf_detach (struct inf *inf)
gnu_nat_target::inf_detach (struct inf *inf)
{
struct proc *task = inf->task;
@ -1293,7 +1263,7 @@ inf_detach (struct inf *inf)
/* Attaches INF to the process with process id PID, returning it in a
suspended state suitable for debugging. */
void
inf_attach (struct inf *inf, int pid)
gnu_nat_target::inf_attach (struct inf *inf, int pid)
{
inf_debug (inf, "attaching: %d", pid);
@ -1306,7 +1276,7 @@ inf_attach (struct inf *inf, int pid)
/* Makes sure that we've got our exception ports entrenched in the process. */
void
inf_steal_exc_ports (struct inf *inf)
gnu_nat_target::inf_steal_exc_ports (struct inf *inf)
{
struct proc *thread;
@ -1321,7 +1291,7 @@ inf_steal_exc_ports (struct inf *inf)
/* Makes sure the process has its own exception ports. */
void
inf_restore_exc_ports (struct inf *inf)
gnu_nat_target::inf_restore_exc_ports (struct inf *inf)
{
struct proc *thread;
@ -1339,7 +1309,7 @@ inf_restore_exc_ports (struct inf *inf)
signal 0, will continue it. INF is assumed to be in a paused state, and
the resume_sc's of INF's threads may be affected. */
void
inf_signal (struct inf *inf, enum gdb_signal sig)
gnu_nat_target::inf_signal (struct inf *inf, enum gdb_signal sig)
{
kern_return_t err = 0;
int host_sig = gdb_signal_to_host (sig);
@ -1427,7 +1397,7 @@ inf_signal (struct inf *inf, enum gdb_signal sig)
/* Continue INF without delivering a signal. This is meant to be used
when INF does not have a message port. */
void
inf_continue (struct inf *inf)
gnu_nat_target::inf_continue (struct inf *inf)
{
process_t proc;
kern_return_t err = proc_pid2proc (proc_server, inf->pid, &proc);
@ -1458,7 +1428,7 @@ struct inf *gnu_current_inf = 0;
/* The inferior being waited for by gnu_wait. Since GDB is decidely not
multi-threaded, we don't bother to lock this. */
struct inf *waiting_inf;
static struct inf *waiting_inf;
/* MIG stubs are not yet ready for C++ compilation. */
extern "C" int exc_server (mach_msg_header_t *, mach_msg_header_t *);
@ -1852,7 +1822,7 @@ S_proc_wait_reply (mach_port_t reply, kern_return_t err,
inf->no_wait = 1;
/* Since we can't see the inferior's signals, don't trap them. */
inf_set_traced (inf, 0);
gnu_target->inf_set_traced (inf, 0);
}
}
else if (pid == inf->pid)
@ -2155,7 +2125,7 @@ gnu_nat_target::create_inferior (const char *exec_file,
/* We have something that executes now. We'll be running through
the shell at this point (if startup-with-shell is true), but the
pid shouldn't change. */
add_thread_silent (gnu_target, ptid_t (pid));
add_thread_silent (this, ptid_t (pid));
/* Attach to the now stopped child, which is actually a shell... */
inf_debug (inf, "attaching to child: %d", pid);
@ -2171,7 +2141,7 @@ gnu_nat_target::create_inferior (const char *exec_file,
inf_resume (inf);
/* We now have thread info. */
thread_change_ptid (gnu_target, inferior_ptid,
thread_change_ptid (this, inferior_ptid,
ptid_t (inf->pid, inf_pick_first_thread (), 0));
gdb_startup_inferior (pid, START_INFERIOR_TRAPS_EXPECTED);
@ -2277,7 +2247,7 @@ gnu_nat_target::detach (inferior *inf, int from_tty)
inf_detach (gnu_current_inf);
inferior_ptid = null_ptid;
detach_inferior (find_inferior_pid (gnu_target, pid));
detach_inferior (find_inferior_pid (this, pid));
maybe_unpush_target ();
}
@ -2842,7 +2812,7 @@ set_task_pause_cmd (int arg, int from_tty)
if (old_sc == 0 && inf->pause_sc != 0)
/* If the task is currently unsuspended, immediately suspend it,
otherwise wait until the next time it gets control. */
inf_suspend (inf);
gnu_target->inf_suspend (inf);
}
static void
@ -2938,8 +2908,8 @@ show_thread_default_detach_sc_cmd (const char *args, int from_tty)
/* Steal a send right called NAME in the inferior task, and make it PROC's
saved exception port. */
static void
steal_exc_port (struct proc *proc, mach_port_t name)
void
gnu_nat_target::steal_exc_port (struct proc *proc, mach_port_t name)
{
kern_return_t err;
mach_port_t port;
@ -2980,7 +2950,7 @@ set_task_exc_port_cmd (const char *args, int from_tty)
if (!args)
error (_("No argument to \"set task exception-port\" command."));
steal_exc_port (inf->task, parse_and_eval_address (args));
gnu_target->steal_exc_port (inf->task, parse_and_eval_address (args));
}
static void
@ -3040,7 +3010,7 @@ set_signals_cmd (int arg, int from_tty)
if (inf->task && inf->want_signals != inf->traced)
/* Make this take effect immediately in a running process. */
inf_set_traced (inf, inf->want_signals);
gnu_target->inf_set_traced (inf, inf->want_signals);
}
static void
@ -3338,7 +3308,7 @@ set_thread_pause_cmd (const char *args, int from_tty)
if (old_sc == 0 && thread->pause_sc != 0 && thread->inf->pause_sc == 0)
/* If the task is currently unsuspended, immediately suspend it,
otherwise wait until the next time it gets control. */
inf_suspend (thread->inf);
gnu_target->inf_suspend (thread->inf);
}
static void
@ -3399,7 +3369,7 @@ set_thread_exc_port_cmd (const char *args, int from_tty)
if (!args)
error (_("No argument to \"set thread exception-port\" command."));
steal_exc_port (thread, parse_and_eval_address (args));
gnu_target->steal_exc_port (thread, parse_and_eval_address (args));
}
#if 0

View File

@ -96,12 +96,6 @@ struct proc
extern int __proc_pid (struct proc *proc);
/* Make sure that the state field in PROC is up to date, and return a
pointer to it, or 0 if something is wrong. If WILL_MODIFY is true,
makes sure that the thread is stopped and aborted first, and sets
the state_changed field in PROC to true. */
extern thread_state_t proc_get_state (struct proc *proc, int will_modify);
/* Return printable description of proc. */
extern char *proc_string (struct proc *proc);
@ -148,6 +142,49 @@ struct gnu_nat_target : public inf_child_target
bool thread_alive (ptid_t ptid) override;
std::string pid_to_str (ptid_t) override;
void stop (ptid_t) override;
void inf_validate_procs (struct inf *inf);
void inf_suspend (struct inf *inf);
void inf_set_traced (struct inf *inf, int on);
void steal_exc_port (struct proc *proc, mach_port_t name);
/* Make sure that the state field in PROC is up to date, and return a
pointer to it, or 0 if something is wrong. If WILL_MODIFY is true,
makes sure that the thread is stopped and aborted first, and sets
the state_changed field in PROC to true. */
thread_state_t proc_get_state (struct proc *proc, int will_modify);
private:
void inf_clear_wait (struct inf *inf);
void inf_cleanup (struct inf *inf);
void inf_startup (struct inf *inf, int pid);
int inf_update_suspends (struct inf *inf);
void inf_set_pid (struct inf *inf, pid_t pid);
void inf_steal_exc_ports (struct inf *inf);
void inf_validate_procinfo (struct inf *inf);
void inf_validate_task_sc (struct inf *inf);
void inf_restore_exc_ports (struct inf *inf);
void inf_set_threads_resume_sc (struct inf *inf,
struct proc *run_thread,
int run_others);
int inf_set_threads_resume_sc_for_signal_thread (struct inf *inf);
void inf_resume (struct inf *inf);
void inf_set_step_thread (struct inf *inf, struct proc *proc);
void inf_detach (struct inf *inf);
void inf_attach (struct inf *inf, int pid);
void inf_signal (struct inf *inf, enum gdb_signal sig);
void inf_continue (struct inf *inf);
struct proc *make_proc (struct inf *inf, mach_port_t port, int tid);
void proc_abort (struct proc *proc, int force);
struct proc *_proc_free (struct proc *proc);
int proc_update_sc (struct proc *proc);
kern_return_t proc_get_exception_port (struct proc *proc, mach_port_t * port);
kern_return_t proc_set_exception_port (struct proc *proc, mach_port_t port);
mach_port_t _proc_get_exc_port (struct proc *proc);
void proc_steal_exc_port (struct proc *proc, mach_port_t exc_port);
void proc_restore_exc_port (struct proc *proc);
int proc_trace (struct proc *proc, int set);
};
/* The final/concrete instance. */