/* Forward decls */
extern struct target_ops gnu_ops;
+extern char *strerror();
-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, task_t task);
-int inf_update_suspends (struct inf *inf);
-void inf_set_task (struct inf *inf, task_t port);
-void inf_validate_procs (struct inf *inf);
-void inf_steal_exc_ports (struct inf *inf);
-void inf_restore_exc_ports (struct inf *inf);
int inf_update_procs (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);
+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);
#define inf_debug(_inf, msg, args...) \
do { struct inf *__inf = (_inf); \
debug ("{inf %d %p}: " msg, __inf->pid, __inf , ##args); } while (0)
-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);
void proc_abort (struct proc *proc, int force);
thread_state_t proc_get_state (struct proc *proc, int force);
-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 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);
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);
+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);
char *proc_string (struct proc *proc);
/* Evaluate RPC_EXPR in a scope with the variables MSGPORT and REFPORT bound
int want_exceptions;
};
+
int __proc_pid (struct proc *proc)
{
return proc->inf->pid;
\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. */
-int
+static int
proc_update_sc (struct proc *proc)
{
int running;
return 0;
}
\f
-error_t
+/* Set PORT to PROC's exception port. */
+static error_t
proc_get_exception_port (struct proc *proc, mach_port_t *port)
{
if (proc_is_task (proc))
return thread_get_exception_port (proc->port, port);
}
-error_t
+/* Set PROC's exception port to PORT. */
+static 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. */
-void
+static 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 be overwritten,
- in which case who knows what's going on. */
-void
+/* 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
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 fals,
+/* Turns hardware tracing in PROC on or off when SET is true or false,
respectively. Returns true on success. */
-int
+static int
proc_trace (struct proc *proc, int set)
{
thread_state_t state = proc_get_state (proc, 1);
return proc;
}
-/* Frees PROC and any resources it uses, and returns the value of PROC's next
- field. */
-struct proc *
+/* Frees PROC and any resources it uses, and returns the value of PROC's
+ next field. */
+static struct proc *
_proc_free (struct proc *proc)
{
struct inf *inf = proc->inf;
return inf;
}
-void
+/* clear INF's target wait status. */
+static void
inf_clear_wait (struct inf *inf)
{
inf_debug (inf, "clearing wait");
}
}
\f
-void
+static void
inf_cleanup (struct inf *inf)
{
inf_debug (inf, "cleanup");
}
}
-void
+static void
inf_startup (struct inf *inf, int pid, task_t task)
{
error_t err;
}
}
\f
-void
+/* close current process, if any, and attach INF to process PORT */
+static void
inf_set_task (struct inf *inf, mach_port_t port)
{
struct proc *task = inf->task;
/* 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. */
-void
+static 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.*/
-int
+static 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. */
-struct proc *
+static 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. */
-void
+static 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. */
-inline void
+static 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). */
-inline void
+static inline void
inf_resume (struct inf *inf)
{
struct proc *thread;
/* Cause INF to stop execution immediately; individual threads may still
be running. */
-inline void
+static inline void
inf_suspend (struct inf *inf)
{
struct proc *thread;
inf_update_suspends (inf);
}
\f
-/* INF has one thread PROC that is in single-stepping mode. This functions
+/* 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 an any existing value. */
-void
+ PROC of 0 clears any existing value. */
+static 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. */
-inline int
+static 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... */
-void
+static 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. */
-void
+static void
inf_attach (struct inf *inf, int pid)
{
error_t err;
/* 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. */
-void
+static void
inf_signal (struct inf *inf, enum target_signal sig)
{
error_t err = 0;
else
/* A Unix signal. */
if (inf->stopped)
- /* The process is stopped an expecting a signal. Just send off a
+ /* The process is stopped and expecting a signal. Just send off a
request and let it get handled when we resume everything. */
{
inf_debug (inf, "sending %s to stopped process", NAME);
/* 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! */
{
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);
}
if (inf_update_procs (inf) && inf->threads)
tid = inf->threads->tid; /* The first available thread. */
else
- tid = -1;
+ tid = inferior_pid; /* let wait_for_inferior handle exit case */
if (thread && tid >= 0 && status->kind != TARGET_WAITKIND_SPURIOUS
&& inf->pause_sc == 0 && thread->pause_sc == 0)
\f
/* Fill in INF's wait field after a task has died without giving us more
detailed information. */
-void
+static void
inf_task_died_status (struct inf *inf)
{
warning ("Pid %d died with unknown exit status, using SIGKILL.", inf->pid);
/* Fork an inferior process, and start debugging it. */
/* Set INFERIOR_PID to the first thread available in the child, if any. */
-static void
-pick_first_thread ()
+static int
+inf_pick_first_thread ()
{
if (current_inferior->task && current_inferior->threads)
/* The first thread. */
- inferior_pid = current_inferior->threads->tid;
+ return current_inferior->threads->tid;
else
/* What may be the next thread. */
- inferior_pid = next_thread_id;
+ return next_thread_id;
}
static struct inf *
inf_debug (inf, "attaching to child: %d", pid);
inf_attach (inf, pid);
- pick_first_thread ();
attach_flag = 0;
push_target (&gnu_ops);
/* Now let the child run again, knowing that it will stop immediately
because of the ptrace. */
inf_resume (inf);
+ inferior_pid = inf_pick_first_thread ();
- startup_inferior (pid, inf->pending_execs);
+ startup_inferior (inf->pending_execs);
- return pid;
+ return inferior_pid;
}
inf_debug (inf, "creating inferior");
inf_attach (inf, pid);
inf_update_procs (inf);
- pick_first_thread ();
+ inferior_pid = inf_pick_first_thread ();
attach_flag = 1;
push_target (&gnu_ops);
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. */
renumber_threads (0); /* Give our threads reasonable names. */
+#endif
}
\f
/* Take a program previously attached to and detaches it.
struct obstack region_obstack;
/*
- * Write inferior task's LEN bytes from ADDR and copy it to MYADDR
- * in gdb's address space.
+ * Write gdb's LEN bytes from MYADDR and copy it to ADDR
+ * in inferior task's address space.
*/
int
gnu_write_inferior (task, addr, myaddr, length)
OPS_MAGIC /* to_magic */
};
\f
+/* Return printable description of proc. */
char *proc_string (struct proc *proc)
{
static char tid_str[80];
else
sprintf (tid_str, "thread %d.%d",
proc->inf->pid,
- pid_to_thread_id (proc->tid));
+#if 0
+ pid_to_thread_id (proc->tid)
+#else
+ proc->tid
+#endif
+);
return tid_str;
}
struct cmd_list_element *set_task_cmd_list = 0;
struct cmd_list_element *show_task_cmd_list = 0;
+/* User thread commands. */
+
+/* Commands with a prefix of `set/show thread'. */
+extern struct cmd_list_element *thread_cmd_list;
+struct cmd_list_element *set_thread_cmd_list = NULL;
+struct cmd_list_element *show_thread_cmd_list = NULL;
+
+/* Commands with a prefix of `set/show thread default'. */
+struct cmd_list_element *set_thread_default_cmd_list = NULL;
+struct cmd_list_element *show_thread_default_cmd_list = NULL;
+
+static void
+set_thread_cmd (char *args, int from_tty)
+{
+ printf_unfiltered ("\"set thread\" must be followed by the name of a thread
+property, or \"default\".\n");
+}
+
+static void
+show_thread_cmd (char *args, int from_tty)
+{
+ printf_unfiltered ("\"show thread\" must be followed by the name of a thread property, or \"default\".\n");
+}
+
+static void
+set_thread_default_cmd (char *args, int from_tty)
+{
+ printf_unfiltered ("\"set thread default\" must be followed by the name of a thread property.\n");
+}
-extern struct cmd_list_element *set_thread_default_cmd_list;
-extern struct cmd_list_element *show_thread_default_cmd_list;
+static void
+show_thread_default_cmd (char *args, int from_tty)
+{
+ printf_unfiltered ("\"show thread default\" must be followed by the name of a thread property.\n");
+}
static int
parse_int_arg (char *args, char *cmd_prefix)
add_info_alias ("psets", "port-sets", 1);
}
\f
-/* User thread commands. */
-
-extern struct cmd_list_element *set_thread_cmd_list;
-extern struct cmd_list_element *show_thread_cmd_list;
-extern struct cmd_list_element *thread_cmd_list;
static void
set_thread_pause_cmd (char *args, int from_tty)
steal_exc_port (thread, parse_and_eval_address (args));
}
-static void
-set_thread_cmd (char *args, int from_tty)
-{
- printf_unfiltered ("\"set thread\" must be followed by the name of a thread property.\n");
-}
-
+#if 0
static void
show_thread_cmd (char *args, int from_tty)
{
if (thread->detach_sc != 0)
show_thread_detach_sc_cmd (0, from_tty);
}
+#endif
static void
thread_takeover_sc_cmd (char *args, int from_tty)
add_thread_commands ()
{
+ add_prefix_cmd ("thread", no_class, set_thread_cmd,
+ "Command prefix for setting thread properties.",
+ &set_thread_cmd_list, "set thread ", 0, &setlist);
+ add_prefix_cmd ("default", no_class, show_thread_cmd,
+ "Command prefix for setting default thread properties.",
+ &set_thread_default_cmd_list, "set thread default ", 0,
+ &set_thread_cmd_list);
+ add_prefix_cmd ("thread", no_class, set_thread_default_cmd,
+ "Command prefix for showing thread properties.",
+ &show_thread_cmd_list, "show thread ", 0, &showlist);
+ add_prefix_cmd ("default", no_class, show_thread_default_cmd,
+ "Command prefix for showing default thread properties.",
+ &show_thread_default_cmd_list, "show thread default ", 0,
+ &show_thread_cmd_list);
+
add_cmd ("pause", class_run, set_thread_pause_cmd,
"Set whether the current thread is suspended while gdb has control.\n"
"A value of \"on\" takes effect immediately, otherwise nothing\n"