/* Interface GDB to the GNU Hurd
- Copyright (C) 1992, 1995, 1996 Free Software Foundation, Inc.
+ Copyright (C) 1992, 1995, 1996, 1997 Free Software Foundation, Inc.
This file is part of GDB.
#include "notify_S.h"
#include "process_reply_S.h"
#include "msg_reply_S.h"
-
#include "exc_request_U.h"
#include "msg_U.h"
extern char *strerror();
int inf_update_procs (struct inf *inf);
-static struct inf *make_inf ();
-static void inf_clear_wait (struct inf *inf);
-static void inf_cleanup (struct inf *inf);
-static void inf_startup (struct inf *inf, int pid, task_t task);
-static int inf_update_suspends (struct inf *inf);
-static void inf_set_task (struct inf *inf, task_t port);
-static void inf_validate_procs (struct inf *inf);
-static void inf_steal_exc_ports (struct inf *inf);
-static void inf_restore_exc_ports (struct inf *inf);
-static struct proc *inf_tid_to_proc (struct inf *inf, int tid);
-static inline void inf_set_threads_resume_sc (struct inf *inf,
- struct proc *run_thread,
- int run_others);
-static inline int inf_set_threads_resume_sc_for_signal_thread (struct inf *inf);
-static inline void inf_suspend (struct inf *inf);
-static inline void inf_resume (struct inf *inf);
-static void inf_set_step_thread (struct inf *inf, struct proc *proc);
-static void inf_detach (struct inf *inf);
-static void inf_attach (struct inf *inf, int pid);
-static void inf_signal (struct inf *inf, enum target_signal sig);
+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);
+struct proc *inf_tid_to_proc (struct inf *inf, int tid);
+inline void inf_set_threads_resume_sc (struct inf *inf,
+ struct proc *run_thread,
+ int run_others);
+inline int inf_set_threads_resume_sc_for_signal_thread (struct inf *inf);
+inline void inf_suspend (struct inf *inf);
+inline 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 target_signal sig);
#define inf_debug(_inf, msg, args...) \
do { struct inf *__inf = (_inf); \
void proc_abort (struct proc *proc, int force);
thread_state_t proc_get_state (struct proc *proc, int force);
-static struct proc *make_proc (struct inf *inf, mach_port_t port, int tid);
-static struct proc *_proc_free (struct proc *proc);
-static int proc_update_sc (struct proc *proc);
-static error_t proc_get_exception_port (struct proc *proc, mach_port_t *port);
-static error_t proc_set_exception_port (struct proc *proc, mach_port_t port);
+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);
+error_t proc_get_exception_port (struct proc *proc, mach_port_t *port);
+error_t proc_set_exception_port (struct proc *proc, mach_port_t port);
static mach_port_t _proc_get_exc_port (struct proc *proc);
-static void proc_steal_exc_port (struct proc *proc, mach_port_t exc_port);
-static void proc_restore_exc_port (struct proc *proc);
-static int proc_trace (struct proc *proc, int set);
+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);
char *proc_string (struct proc *proc);
/* Evaluate RPC_EXPR in a scope with the variables MSGPORT and REFPORT bound
\f
/* Update PROC's real suspend count to match it's desired one. Returns true
if we think PROC is now in a runnable state. */
-static int
+int
proc_update_sc (struct proc *proc)
{
int running;
}
\f
/* Set PORT to PROC's exception port. */
-static error_t
+error_t
proc_get_exception_port (struct proc *proc, mach_port_t *port)
{
if (proc_is_task (proc))
}
/* Set PROC's exception port to PORT. */
-static error_t
+error_t
proc_set_exception_port (struct proc *proc, mach_port_t port)
{
proc_debug (proc, "setting exception port: %d", port);
/* Replace PROC's exception port with EXC_PORT, unless it's already been
done. Stash away any existing exception port so we can restore it later. */
-static void
+void
proc_steal_exc_port (struct proc *proc, mach_port_t exc_port)
{
mach_port_t cur_exc_port = _proc_get_exc_port (proc);
/* If we previously replaced PROC's exception port, put back what we
found there at the time, unless *our* exception port has since been
overwritten, in which case who knows what's going on. */
-static void
+void
proc_restore_exc_port (struct proc *proc)
{
mach_port_t cur_exc_port = _proc_get_exc_port (proc);
\f
/* Turns hardware tracing in PROC on or off when SET is true or false,
respectively. Returns true on success. */
-static int
+int
proc_trace (struct proc *proc, int set)
{
thread_state_t state = proc_get_state (proc, 1);
/* Frees PROC and any resources it uses, and returns the value of PROC's
next field. */
-static struct proc *
+struct proc *
_proc_free (struct proc *proc)
{
struct inf *inf = proc->inf;
}
/* clear INF's target wait status. */
-static void
+void
inf_clear_wait (struct inf *inf)
{
inf_debug (inf, "clearing wait");
}
}
\f
-static void
+void
inf_cleanup (struct inf *inf)
{
inf_debug (inf, "cleanup");
inf_clear_wait (inf);
- inf_set_task (inf, MACH_PORT_NULL);
+ inf_set_pid (inf, -1);
inf->pid = 0;
inf->traced = 0;
inf->no_wait = 0;
}
}
-static void
-inf_startup (struct inf *inf, int pid, task_t task)
+void
+inf_startup (struct inf *inf, int pid)
{
error_t err;
- inf_debug (inf, "startup: pid = %d, task = %d", pid, task);
+ inf_debug (inf, "startup: pid = %d", pid);
inf_cleanup (inf);
/* Make a send right for it, so we can easily copy it for other people. */
mach_port_insert_right (mach_task_self (), inf->event_port,
inf->event_port, MACH_MSG_TYPE_MAKE_SEND);
-
- if (inf->pause_sc)
- task_suspend (task);
-
- inf_set_task (inf, task);
-
- if (inf->task)
- {
- inf->pid = pid;
- if (inf->pause_sc)
- inf->task->sc = inf->task->cur_sc = 1; /* Reflect task_suspend above */
- }
+ inf_set_pid (inf, pid);
}
\f
/* close current process, if any, and attach INF to process PORT */
-static void
-inf_set_task (struct inf *inf, mach_port_t port)
+void
+inf_set_pid (struct inf *inf, pid_t pid)
{
+ task_t task_port;
struct proc *task = inf->task;
- inf_debug (inf, "setting task: %d", port);
+ inf_debug (inf, "setting pid: %d", pid);
- if (task && task->port != port)
+ if (pid < 0)
+ task_port = MACH_PORT_NULL;
+ else
+ {
+ error_t err = proc_pid2task (proc_server, pid, &task_port);
+ if (err)
+ error ("Error getting task for pid %d: %s", pid, strerror (err));
+ }
+
+ inf_debug (inf, "setting task: %d", task_port);
+
+ if (inf->pause_sc)
+ task_suspend (task_port);
+
+ if (task && task->port != task_port)
{
inf->task = 0;
inf_validate_procs (inf); /* Trash all the threads. */
_proc_free (task); /* And the task. */
}
- if (port != MACH_PORT_NULL)
+ if (task_port != MACH_PORT_NULL)
{
- inf->task = make_proc (inf, port, PROC_TID_TASK);
+ inf->task = make_proc (inf, task_port, PROC_TID_TASK);
inf->threads_up_to_date = 0;
}
+
+ if (inf->task)
+ {
+ inf->pid = pid;
+ if (inf->pause_sc)
+ inf->task->sc = inf->task->cur_sc = 1; /* Reflect task_suspend above */
+ }
+ else
+ inf->pid = -1;
}
\f
/* Validates INF's stopped field from the actual proc server state. */
/* Turns tracing for INF on or off, depending on ON, unless it already 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
+void
inf_set_traced (struct inf *inf, int on)
{
if (on != inf->traced)
/* Makes all the real suspend count deltas of all the procs in INF match the
desired values. Careful to always do thread/task suspend counts in the
safe order. Returns true if at least one thread is thought to be running.*/
-static int
+int
inf_update_suspends (struct inf *inf)
{
struct proc *task = inf->task;
inf_tid_to_thread (struct inf *inf, int tid)
{
struct proc *thread = inf->threads;
- if (tid == inf->pid) /* main thread */
- return thread;
+
while (thread)
if (thread->tid == tid)
return thread;
}
/* Converts a thread port to a struct proc. */
-static struct proc *
+struct proc *
inf_port_to_thread (struct inf *inf, mach_port_t port)
{
struct proc *thread = inf->threads;
}
\f
/* Make INF's list of threads be consistent with reality of TASK. */
-static void
+void
inf_validate_procs (struct inf *inf)
{
int i;
else
/* THREADS[I] is a thread we don't know about yet! */
{
-#if 0
thread = make_proc (inf, threads[i], next_thread_id++);
-#else
- thread = make_proc (inf, threads[i], threads[i]);
-#endif
(last ? last->next : inf->threads) = thread;
last = thread;
proc_debug (thread, "new thread: %d", threads[i]);
-#if 1 /* try leaving this out, see what happens */
add_thread (thread->tid); /* Tell GDB's generic thread code. */
-#if 0 /* seems to cause kernel exceptions??? */
- target_terminal_ours_for_output (); /* allow debugger I/O */
- printf_filtered ("[gnu-nat: New %s]\n",
- target_pid_to_str (thread->tid));
- target_terminal_inferior (); /* give it back */
-#endif
-#endif
}
vm_deallocate(mach_task_self(),
/* Sets the resume_sc of each thread in inf. That of RUN_THREAD is set to 0,
and others are set to their run_sc if RUN_OTHERS is true, and otherwise
their pause_sc. */
-static inline void
+inline void
inf_set_threads_resume_sc (struct inf *inf,
struct proc *run_thread, int run_others)
{
\f
/* Cause INF to continue execution immediately; individual threads may still
be suspended (but their suspend counts will be updated). */
-static inline void
+inline void
inf_resume (struct inf *inf)
{
struct proc *thread;
/* Cause INF to stop execution immediately; individual threads may still
be running. */
-static inline void
+inline void
inf_suspend (struct inf *inf)
{
struct proc *thread;
/* INF has one thread PROC that is in single-stepping mode. This function
changes it to be PROC, changing any old step_thread to be a normal one. A
PROC of 0 clears any existing value. */
-static void
+void
inf_set_step_thread (struct inf *inf, struct proc *thread)
{
assert (!thread || proc_is_thread (thread));
/* Set up the thread resume_sc's so that only the signal thread is running
(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. */
-static inline int
+inline int
inf_set_threads_resume_sc_for_signal_thread (struct inf *inf)
{
if (inf->signal_thread)
}
\f
/* Detachs from INF's inferior task, letting it run once again... */
-static void
+void
inf_detach (struct inf *inf)
{
struct proc *task = inf->task;
/* Attaches INF to the process with process id PID, returning it in a suspended
state suitable for debugging. */
-static void
+void
inf_attach (struct inf *inf, int pid)
{
- error_t err;
- task_t task;
-
inf_debug (inf, "attaching: %d", pid);
- err = proc_pid2task (proc_server, pid, &task);
- if (err)
- error ("Error getting task for pid %d: %s", pid, strerror (err));
-
if (inf->pid)
inf_detach (inf);
- inf_startup (inf, pid, task);
+ inf_startup (inf, pid);
}
\f
/* Makes sure that we've got our exception ports entrenched in the process. */
/* Deliver signal SIG to INF. If INF is stopped, delivering a signal, even
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. */
-static void
+void
inf_signal (struct inf *inf, enum target_signal sig)
{
error_t err = 0;
/* Re-suspend the task. */
inf_suspend (inf);
+ if (!inf->task && inf->pending_execs)
+ /* When doing an exec, it's possible that the old task wasn't reused
+ (e.g., setuid execs). So if the task seems to have disappeared,
+ attempt to refetch it, as the pid should still be the same. */
+ inf_set_pid (inf, inf->pid);
+
if (err == EMACH_RCV_INTERRUPTED)
inf_debug (inf, "interrupted");
else if (err)
/* Ah hah! A SIGTRAP from the inferior while starting up probably
means we've succesfully completed an exec! */
{
-#if 0 /* do we need this? */
if (--inf->pending_execs == 0)
/* We're done! */
{
+#if 0 /* do we need this? */
prune_threads (1); /* Get rid of the old shell threads */
renumber_threads (0); /* Give our threads reasonable names. */
- }
#endif
+ }
inf_debug (inf, "pending exec completed, pending_execs => %d",
inf->pending_execs);
}
+ else if (kind == TARGET_WAITKIND_STOPPED)
+ /* It's possible that this signal is because of a crashed process
+ being handled by the hurd crash server; in this case, the process
+ will have an extra task suspend, which we need to know about.
+ Since the code in inf_resume that normally checks for this is
+ disabled while INF->pending_execs, we do the check here instead. */
+ inf_validate_task_sc (inf);
}
if (inf->wait.suppress)
\f
/* Fill in INF's wait field after a task has died without giving us more
detailed information. */
-static void
+void
inf_task_died_status (struct inf *inf)
{
warning ("Pid %d died with unknown exit status, using SIGKILL.", inf->pid);
{
proc_debug (task, "terminating...");
task_terminate (task->port);
- inf_set_task (current_inferior, MACH_PORT_NULL);
+ inf_set_pid (current_inferior, -1);
}
target_mourn_inferior ();
}
inf_debug (inf, "creating inferior");
- fork_inferior (exec_file, allargs, env, trace_me, attach_to_child, NULL);
+ fork_inferior (exec_file, allargs, env, trace_me, attach_to_child, NULL, NULL);
inf_update_signal_thread (inf);
inf_set_traced (inf, inf->want_signals);
time the user does a continue. */
inf_validate_stopped (inf);
-#if 0 /* Do we need this? Actually I can see where it
- might be helpful here, but it's just cosmetic.
- Let's come back to it later. XXX Fix me. */
+#if 0 /* Do we need this? */
renumber_threads (0); /* Give our threads reasonable names. */
#endif
}
error ("to_stop target function not implemented");
}
+static void
+gnu_pid_to_exec_file ()
+{
+ error ("to_pid_to_exec_file target function not implemented");
+}
+
+
static int
gnu_thread_alive (int tid)
{
extern void gnu_store_registers (int regno);
extern void gnu_fetch_registers (int regno);
-struct target_ops gnu_ops = {
- "GNU", /* to_shortname */
- "GNU Hurd process", /* to_longname */
- "GNU Hurd process", /* to_doc */
- gnu_open, /* to_open */
- 0, /* to_close */
- gnu_attach, /* to_attach */
- gnu_detach, /* to_detach */
- gnu_resume, /* to_resume */
- gnu_wait, /* to_wait */
- gnu_fetch_registers, /* to_fetch_registers */
- gnu_store_registers, /* to_store_registers */
- gnu_prepare_to_store, /* to_prepare_to_store */
- gnu_xfer_memory, /* to_xfer_memory */
- 0, /* to_files_info */
- memory_insert_breakpoint, /* to_insert_breakpoint */
- memory_remove_breakpoint, /* to_remove_breakpoint */
- gnu_terminal_init_inferior, /* to_terminal_init */
- terminal_inferior, /* to_terminal_inferior */
- terminal_ours_for_output, /* to_terminal_ours_for_output */
- terminal_ours, /* to_terminal_ours */
- child_terminal_info, /* to_terminal_info */
- gnu_kill_inferior, /* to_kill */
- 0, /* to_load */
- 0, /* to_lookup_symbol */
-
- gnu_create_inferior, /* to_create_inferior */
- gnu_mourn_inferior, /* to_mourn_inferior */
- gnu_can_run, /* to_can_run */
- 0, /* to_notice_signals */
- gnu_thread_alive, /* to_thread_alive */
- gnu_stop, /* to_stop */
- process_stratum, /* to_stratum */
- 0, /* to_next */
- 1, /* to_has_all_memory */
- 1, /* to_has_memory */
- 1, /* to_has_stack */
- 1, /* to_has_registers */
- 1, /* to_has_execution */
- 0, /* sections */
- 0, /* sections_end */
- OPS_MAGIC /* to_magic */
-};
+struct target_ops gnu_ops ;
+
+static void
+init_gnu_ops(void)
+{
+ gnu_ops.to_shortname = "GNU"; /* to_shortname */
+ gnu_ops.to_longname = "GNU Hurd process"; /* to_longname */
+ gnu_ops.to_doc = "GNU Hurd process"; /* to_doc */
+ gnu_ops.to_open = gnu_open; /* to_open */
+ gnu_ops.to_close = 0; /* to_close */
+ gnu_ops.to_attach = gnu_attach; /* to_attach */
+ gnu_ops.to_post_attach = NULL;
+ gnu_ops.to_require_attach = NULL; /* to_require_attach */
+ gnu_ops.to_detach = gnu_detach; /* to_detach */
+ gnu_ops.to_require_detach = NULL; /* to_require_detach */
+ gnu_ops.to_resume = gnu_resume; /* to_resume */
+ gnu_ops.to_wait = gnu_wait; /* to_wait */
+ gnu_ops.to_post_wait = NULL; /* to_post_wait */
+ gnu_ops.to_fetch_registers = gnu_fetch_registers; /* to_fetch_registers */
+ gnu_ops.to_store_registers = gnu_store_registers; /* to_store_registers */
+ gnu_ops.to_prepare_to_store = gnu_prepare_to_store; /* to_prepare_to_store */
+ gnu_ops.to_xfer_memory = gnu_xfer_memory; /* to_xfer_memory */
+ gnu_ops.to_files_info = 0; /* to_files_info */
+ gnu_ops.to_insert_breakpoint = memory_insert_breakpoint;
+ gnu_ops.to_remove_breakpoint = memory_remove_breakpoint;
+ gnu_ops.to_terminal_init = gnu_terminal_init_inferior;
+ gnu_ops.to_terminal_inferior = terminal_inferior;
+ gnu_ops.to_terminal_ours_for_output = terminal_ours_for_output;
+ gnu_ops.to_terminal_ours = terminal_ours;
+ gnu_ops.to_terminal_info = child_terminal_info;
+ gnu_ops.to_kill = gnu_kill_inferior; /* to_kill */
+ gnu_ops.to_load = 0; /* to_load */
+ gnu_ops.to_lookup_symbol = 0; /* to_lookup_symbol */
+ gnu_ops.to_create_inferior = gnu_create_inferior; /* to_create_inferior */
+ gnu_ops.to_post_startup_inferior = NULL; /* to_post_startup_inferior */
+ gnu_ops.to_acknowledge_created_inferior = NULL; /* to_acknowledge_created_inferior */
+ gnu_ops.to_clone_and_follow_inferior = NULL; /* to_clone_and_follow_inferior */
+ gnu_ops.to_post_follow_inferior_by_clone = NULL; /* to_post_follow_inferior_by_clone */
+ gnu_ops.to_insert_fork_catchpoint = NULL;
+ gnu_ops.to_remove_fork_catchpoint = NULL;
+ gnu_ops.to_insert_vfork_catchpoint = NULL;
+ gnu_ops.to_remove_vfork_catchpoint = NULL;
+ gnu_ops.to_has_forked = NULL; /* to_has_forked */
+ gnu_ops.to_has_vforked = NULL; /* to_has_vforked */
+ gnu_ops.to_can_follow_vfork_prior_to_exec = NULL;
+ gnu_ops.to_post_follow_vfork = NULL; /* to_post_follow_vfork */
+ gnu_ops.to_insert_exec_catchpoint = NULL;
+ gnu_ops.to_remove_exec_catchpoint = NULL;
+ gnu_ops.to_has_execd = NULL;
+ gnu_ops.to_reported_exec_events_per_exec_call = NULL;
+ gnu_ops.to_has_exited = NULL;
+ gnu_ops.to_mourn_inferior = gnu_mourn_inferior; /* to_mourn_inferior */
+ gnu_ops.to_can_run = gnu_can_run; /* to_can_run */
+ gnu_ops.to_notice_signals = 0; /* to_notice_signals */
+ gnu_ops.to_thread_alive = gnu_thread_alive;/* to_thread_alive */
+ gnu_ops.to_stop = gnu_stop; /* to_stop */
+ gnu_ops.to_pid_to_exec_file = gnu_pid_to_exec_file; /* to_pid_to_exec_file */
+ gnu_ops.to_core_file_to_sym_file = NULL;
+ gnu_ops.to_stratum = process_stratum; /* to_stratum */
+ gnu_ops.DONT_USE = 0; /* to_next */
+ gnu_ops.to_has_all_memory = 1; /* to_has_all_memory */
+ gnu_ops.to_has_memory = 1; /* to_has_memory */
+ gnu_ops.to_has_stack = 1; /* to_has_stack */
+ gnu_ops.to_has_registers = 1; /* to_has_registers */
+ gnu_ops.to_has_execution = 1; /* to_has_execution */
+ gnu_ops.to_sections = 0; /* sections */
+ gnu_ops.to_sections_end = 0; /* sections_end */
+ gnu_ops.to_magic = OPS_MAGIC ; /* to_magic */
+} /* init_gnu_ops */
\f
/* Return printable description of proc. */
char *proc_string (struct proc *proc)
sprintf (tid_str, "process %d", proc->inf->pid);
else
sprintf (tid_str, "thread %d.%d",
- proc->inf->pid,
-#if 0
- pid_to_thread_id (proc->tid)
-#else
- proc->tid
-#endif
-);
+ proc->inf->pid, pid_to_thread_id (proc->tid));
return tid_str;
}
_initialize_gnu_nat ()
{
proc_server = getproc ();
-
+ init_gnu_ops() ;
add_target (&gnu_ops);
-
add_task_commands ();
add_thread_commands ();