/* Async mode support */
-/* True if async mode is currently on. */
-static int linux_nat_async_enabled;
-
/* Zero if the async mode, although enabled, is masked, which means
linux_nat_wait should behave as if async mode was off. */
static int linux_nat_async_mask_value = 1;
}
else
{
+ struct thread_info *last_tp = find_thread_pid (last_ptid);
+ struct thread_info *tp;
char child_pid_spelling[40];
+ /* Copy user stepping state to the new inferior thread. */
+ struct breakpoint *step_resume_breakpoint = last_tp->step_resume_breakpoint;
+ CORE_ADDR step_range_start = last_tp->step_range_start;
+ CORE_ADDR step_range_end = last_tp->step_range_end;
+ struct frame_id step_frame_id = last_tp->step_frame_id;
+
+ /* Otherwise, deleting the parent would get rid of this
+ breakpoint. */
+ last_tp->step_resume_breakpoint = NULL;
+
/* Needed to keep the breakpoint lists in sync. */
if (! has_vforked)
detach_breakpoints (child_pid);
linux_nat_switch_fork (inferior_ptid);
check_for_thread_db ();
+ tp = inferior_thread ();
+ tp->step_resume_breakpoint = step_resume_breakpoint;
+ tp->step_range_start = step_range_start;
+ tp->step_range_end = step_range_end;
+ tp->step_frame_id = step_frame_id;
+
/* Reset breakpoints in the child as appropriate. */
follow_inferior_reset_breakpoints ();
}
{
struct lwp_info *lp;
int status;
+ ptid_t ptid;
/* FIXME: We should probably accept a list of process id's, and
attach all of them. */
sigdelset (&suspend_mask, SIGCHLD);
}
+ /* The ptrace base target adds the main thread with (pid,0,0)
+ format. Decorate it with lwp info. */
+ ptid = BUILD_LWP (GET_PID (inferior_ptid), GET_PID (inferior_ptid));
+ thread_change_ptid (inferior_ptid, ptid);
+
/* Add the initial process as the first LWP to the list. */
- inferior_ptid = BUILD_LWP (GET_PID (inferior_ptid), GET_PID (inferior_ptid));
- lp = add_lwp (inferior_ptid);
+ lp = add_lwp (ptid);
status = linux_nat_post_attach_wait (lp->ptid, 1, &lp->cloned,
&lp->signalled);
lp->stopped = 1;
- /* If this process is not using thread_db, then we still don't
- detect any other threads, but add at least this one. */
- add_thread_silent (lp->ptid);
-
/* Save the wait status to report later. */
lp->resumed = 1;
if (debug_linux_nat)
{
/* If the core knows the thread is not executing, then we
have the last signal recorded in
- thread_info->stop_signal, unless this is inferior_ptid,
- in which case, it's in the global stop_signal, due to
- context switching. */
+ thread_info->stop_signal. */
- if (ptid_equal (lp->ptid, inferior_ptid))
- signo = stop_signal;
- else
- {
- struct thread_info *tp = find_thread_pid (lp->ptid);
- gdb_assert (tp);
- signo = tp->stop_signal;
- }
+ struct thread_info *tp = find_thread_pid (lp->ptid);
+ signo = tp->stop_signal;
}
if (signo != TARGET_SIGNAL_0
{
if (GET_LWP (lp->ptid) == GET_LWP (last_ptid))
{
- if (stop_signal != TARGET_SIGNAL_0
- && signal_pass_state (stop_signal))
- *status = W_STOPCODE (target_signal_to_host (stop_signal));
+ struct thread_info *tp = find_thread_pid (lp->ptid);
+ if (tp->stop_signal != TARGET_SIGNAL_0
+ && signal_pass_state (tp->stop_signal))
+ *status = W_STOPCODE (target_signal_to_host (tp->stop_signal));
}
else if (target_can_async_p ())
queued_waitpid (GET_LWP (lp->ptid), status, __WALL);
lp->step = 0;
memset (&lp->siginfo, 0, sizeof (lp->siginfo));
}
+ else if (lp->stopped && debug_linux_nat)
+ fprintf_unfiltered (gdb_stdlog, "RC: Not resuming sibling %s (has pending)\n",
+ target_pid_to_str (lp->ptid));
+ else if (debug_linux_nat)
+ fprintf_unfiltered (gdb_stdlog, "RC: Not resuming sibling %s (not stopped)\n",
+ target_pid_to_str (lp->ptid));
return 0;
}
return 0;
}
-/* Wait until LP is stopped. If DATA is non-null it is interpreted as
- a pointer to a set of signals to be flushed immediately. */
+/* Return non-zero if LWP PID has a pending SIGINT. */
static int
-stop_wait_callback (struct lwp_info *lp, void *data)
+linux_nat_has_pending_sigint (int pid)
{
- sigset_t *flush_mask = data;
+ sigset_t pending, blocked, ignored;
+ int i;
+
+ linux_proc_pending_signals (pid, &pending, &blocked, &ignored);
+
+ if (sigismember (&pending, SIGINT)
+ && !sigismember (&ignored, SIGINT))
+ return 1;
+ return 0;
+}
+
+/* Set a flag in LP indicating that we should ignore its next SIGINT. */
+
+static int
+set_ignore_sigint (struct lwp_info *lp, void *data)
+{
+ /* If a thread has a pending SIGINT, consume it; otherwise, set a
+ flag to consume the next one. */
+ if (lp->stopped && lp->status != 0 && WIFSTOPPED (lp->status)
+ && WSTOPSIG (lp->status) == SIGINT)
+ lp->status = 0;
+ else
+ lp->ignore_sigint = 1;
+
+ return 0;
+}
+
+/* If LP does not have a SIGINT pending, then clear the ignore_sigint flag.
+ This function is called after we know the LWP has stopped; if the LWP
+ stopped before the expected SIGINT was delivered, then it will never have
+ arrived. Also, if the signal was delivered to a shared queue and consumed
+ by a different thread, it will never be delivered to this LWP. */
+
+static void
+maybe_clear_ignore_sigint (struct lwp_info *lp)
+{
+ if (!lp->ignore_sigint)
+ return;
+
+ if (!linux_nat_has_pending_sigint (GET_LWP (lp->ptid)))
+ {
+ if (debug_linux_nat)
+ fprintf_unfiltered (gdb_stdlog,
+ "MCIS: Clearing bogus flag for %s\n",
+ target_pid_to_str (lp->ptid));
+ lp->ignore_sigint = 0;
+ }
+}
+
+/* Wait until LP is stopped. */
+
+static int
+stop_wait_callback (struct lwp_info *lp, void *data)
+{
if (!lp->stopped)
{
int status;
if (status == 0)
return 0;
- /* Ignore any signals in FLUSH_MASK. */
- if (flush_mask && sigismember (flush_mask, WSTOPSIG (status)))
+ if (lp->ignore_sigint && WIFSTOPPED (status)
+ && WSTOPSIG (status) == SIGINT)
{
- if (!lp->signalled)
- {
- lp->stopped = 1;
- return 0;
- }
+ lp->ignore_sigint = 0;
errno = 0;
ptrace (PTRACE_CONT, GET_LWP (lp->ptid), 0, 0);
if (debug_linux_nat)
fprintf_unfiltered (gdb_stdlog,
- "PTRACE_CONT %s, 0, 0 (%s)\n",
+ "PTRACE_CONT %s, 0, 0 (%s) (discarding SIGINT)\n",
target_pid_to_str (lp->ptid),
errno ? safe_strerror (errno) : "OK");
- return stop_wait_callback (lp, flush_mask);
+ return stop_wait_callback (lp, NULL);
}
+ maybe_clear_ignore_sigint (lp);
+
if (WSTOPSIG (status) != SIGSTOP)
{
if (WSTOPSIG (status) == SIGTRAP)
}
/* Hold this event/waitstatus while we check to see if
there are any more (we still want to get that SIGSTOP). */
- stop_wait_callback (lp, data);
+ stop_wait_callback (lp, NULL);
if (target_can_async_p ())
{
/* Hold this event/waitstatus while we check to see if
there are any more (we still want to get that SIGSTOP). */
- stop_wait_callback (lp, data);
+ stop_wait_callback (lp, NULL);
/* If the lp->status field is still empty, use it to
hold this event. If not, then this event must be
return 0;
}
-/* Check whether PID has any pending signals in FLUSH_MASK. If so set
- the appropriate bits in PENDING, and return 1 - otherwise return 0. */
-
-static int
-linux_nat_has_pending (int pid, sigset_t *pending, sigset_t *flush_mask)
-{
- sigset_t blocked, ignored;
- int i;
-
- linux_proc_pending_signals (pid, pending, &blocked, &ignored);
-
- if (!flush_mask)
- return 0;
-
- for (i = 1; i < NSIG; i++)
- if (sigismember (pending, i))
- if (!sigismember (flush_mask, i)
- || sigismember (&blocked, i)
- || sigismember (&ignored, i))
- sigdelset (pending, i);
-
- if (sigisemptyset (pending))
- return 0;
-
- return 1;
-}
-
-/* DATA is interpreted as a mask of signals to flush. If LP has
- signals pending, and they are all in the flush mask, then arrange
- to flush them. LP should be stopped, as should all other threads
- it might share a signal queue with. */
-
-static int
-flush_callback (struct lwp_info *lp, void *data)
-{
- sigset_t *flush_mask = data;
- sigset_t pending, intersection, blocked, ignored;
- int pid, status;
-
- /* Normally, when an LWP exits, it is removed from the LWP list. The
- last LWP isn't removed till later, however. So if there is only
- one LWP on the list, make sure it's alive. */
- if (lwp_list == lp && lp->next == NULL)
- if (!linux_nat_thread_alive (lp->ptid))
- return 0;
-
- /* Just because the LWP is stopped doesn't mean that new signals
- can't arrive from outside, so this function must be careful of
- race conditions. However, because all threads are stopped, we
- can assume that the pending mask will not shrink unless we resume
- the LWP, and that it will then get another signal. We can't
- control which one, however. */
-
- if (lp->status)
- {
- if (debug_linux_nat)
- printf_unfiltered (_("FC: LP has pending status %06x\n"), lp->status);
- if (WIFSTOPPED (lp->status) && sigismember (flush_mask, WSTOPSIG (lp->status)))
- lp->status = 0;
- }
-
- /* While there is a pending signal we would like to flush, continue
- the inferior and collect another signal. But if there's already
- a saved status that we don't want to flush, we can't resume the
- inferior - if it stopped for some other reason we wouldn't have
- anywhere to save the new status. In that case, we must leave the
- signal unflushed (and possibly generate an extra SIGINT stop).
- That's much less bad than losing a signal. */
- while (lp->status == 0
- && linux_nat_has_pending (GET_LWP (lp->ptid), &pending, flush_mask))
- {
- int ret;
-
- errno = 0;
- ret = ptrace (PTRACE_CONT, GET_LWP (lp->ptid), 0, 0);
- if (debug_linux_nat)
- fprintf_unfiltered (gdb_stderr,
- "FC: Sent PTRACE_CONT, ret %d %d\n", ret, errno);
-
- lp->stopped = 0;
- stop_wait_callback (lp, flush_mask);
- if (debug_linux_nat)
- fprintf_unfiltered (gdb_stderr,
- "FC: Wait finished; saved status is %d\n",
- lp->status);
- }
-
- return 0;
-}
-
/* Return non-zero if LP has a wait status pending. */
static int
gdb_assert (count != NULL);
- /* Count only LWPs that have a SIGTRAP event pending. */
- if (lp->status != 0
+ /* Count only resumed LWPs that have a SIGTRAP event pending. */
+ if (lp->status != 0 && lp->resumed
&& WIFSTOPPED (lp->status) && WSTOPSIG (lp->status) == SIGTRAP)
(*count)++;
gdb_assert (selector != NULL);
- /* Select only LWPs that have a SIGTRAP event pending. */
- if (lp->status != 0
+ /* Select only resumed LWPs that have a SIGTRAP event pending. */
+ if (lp->status != 0 && lp->resumed
&& WIFSTOPPED (lp->status) && WSTOPSIG (lp->status) == SIGTRAP)
if ((*selector)-- == 0)
return 1;
return NULL;
}
+ /* Make sure we don't report a SIGINT that we have already displayed
+ for another thread. */
+ if (lp->ignore_sigint
+ && WIFSTOPPED (status) && WSTOPSIG (status) == SIGINT)
+ {
+ if (debug_linux_nat)
+ fprintf_unfiltered (gdb_stdlog,
+ "LLW: Delayed SIGINT caught for %s.\n",
+ target_pid_to_str (lp->ptid));
+
+ /* This is a delayed SIGINT. */
+ lp->ignore_sigint = 0;
+
+ registers_changed ();
+ linux_ops->to_resume (pid_to_ptid (GET_LWP (lp->ptid)),
+ lp->step, TARGET_SIGNAL_0);
+ if (debug_linux_nat)
+ fprintf_unfiltered (gdb_stdlog,
+ "LLW: %s %s, 0, 0 (discard SIGINT)\n",
+ lp->step ?
+ "PTRACE_SINGLESTEP" : "PTRACE_CONT",
+ target_pid_to_str (lp->ptid));
+
+ lp->stopped = 0;
+ gdb_assert (lp->resumed);
+
+ /* Discard the event. */
+ return NULL;
+ }
+
/* An interesting event. */
gdb_assert (lp);
return lp;
int options = 0;
int status = 0;
pid_t pid = PIDGET (ptid);
- sigset_t flush_mask;
if (debug_linux_nat_async)
fprintf_unfiltered (gdb_stdlog, "LLW: enter\n");
{
gdb_assert (!is_lwp (inferior_ptid));
- inferior_ptid = BUILD_LWP (GET_PID (inferior_ptid),
- GET_PID (inferior_ptid));
+ /* Upgrade the main thread's ptid. */
+ thread_change_ptid (inferior_ptid,
+ BUILD_LWP (GET_PID (inferior_ptid),
+ GET_PID (inferior_ptid)));
+
lp = add_lwp (inferior_ptid);
lp->resumed = 1;
- /* Add the main thread to GDB's thread list. */
- add_thread_silent (lp->ptid);
- set_running (lp->ptid, 1);
- set_executing (lp->ptid, 1);
}
- sigemptyset (&flush_mask);
-
/* Block events while we're here. */
linux_nat_async_events (sigchld_sync);
if (signo == TARGET_SIGNAL_INT && signal_pass_state (signo) == 0)
{
/* If ^C/BREAK is typed at the tty/console, SIGINT gets
- forwarded to the entire process group, that is, all LWP's
- will receive it. Since we only want to report it once,
- we try to flush it from all LWPs except this one. */
- sigaddset (&flush_mask, SIGINT);
+ forwarded to the entire process group, that is, all LWPs
+ will receive it - unless they're using CLONE_THREAD to
+ share signals. Since we only want to report it once, we
+ mark it as ignored for all LWPs except this one. */
+ iterate_over_lwps (set_ignore_sigint, NULL);
+ lp->ignore_sigint = 0;
}
+ else
+ maybe_clear_ignore_sigint (lp);
}
/* This LWP is stopped now. */
/* ... and wait until all of them have reported back that
they're no longer running. */
- iterate_over_lwps (stop_wait_callback, &flush_mask);
- iterate_over_lwps (flush_callback, &flush_mask);
+ iterate_over_lwps (stop_wait_callback, NULL);
/* If we're not waiting for a specific LWP, choose an event LWP
from among those that have had events. Giving equal priority
static void
sigchld_handler (int signo)
{
- if (linux_nat_async_enabled
+ if (target_async_permitted
&& linux_nat_async_events_state != sigchld_sync
&& signo == SIGCHLD)
/* It is *always* a bug to hit this. */
return 0;
}
+static int
+find_signalled_thread (struct thread_info *info, void *data)
+{
+ if (info->stop_signal != TARGET_SIGNAL_0
+ && ptid_get_pid (info->ptid) == ptid_get_pid (inferior_ptid))
+ return 1;
+
+ return 0;
+}
+
+static enum target_signal
+find_stop_signal (void)
+{
+ struct thread_info *info =
+ iterate_over_threads (find_signalled_thread, NULL);
+
+ if (info)
+ return info->stop_signal;
+ else
+ return TARGET_SIGNAL_0;
+}
+
/* Records the thread's register state for the corefile note
section. */
static char *
linux_nat_do_thread_registers (bfd *obfd, ptid_t ptid,
- char *note_data, int *note_size)
+ char *note_data, int *note_size,
+ enum target_signal stop_signal)
{
gdb_gregset_t gregs;
gdb_fpregset_t fpregs;
char *note_data;
int *note_size;
int num_notes;
+ enum target_signal stop_signal;
};
/* Called by gdbthread.c once per thread. Records the thread's
args->note_data = linux_nat_do_thread_registers (args->obfd,
ti->ptid,
args->note_data,
- args->note_size);
+ args->note_size,
+ args->stop_signal);
args->num_notes++;
return 0;
}
-/* Records the register state for the corefile note section. */
-
-static char *
-linux_nat_do_registers (bfd *obfd, ptid_t ptid,
- char *note_data, int *note_size)
-{
- return linux_nat_do_thread_registers (obfd,
- ptid_build (ptid_get_pid (inferior_ptid),
- ptid_get_pid (inferior_ptid),
- 0),
- note_data, note_size);
-}
-
/* Fills the "to_make_corefile_note" target vector. Builds the note
section for a corefile, and returns it in a malloc buffer. */
thread_args.note_data = note_data;
thread_args.note_size = note_size;
thread_args.num_notes = 0;
+ thread_args.stop_signal = find_stop_signal ();
iterate_over_lwps (linux_nat_corefile_thread_callback, &thread_args);
- if (thread_args.num_notes == 0)
- {
- /* iterate_over_threads didn't come up with any threads; just
- use inferior_ptid. */
- note_data = linux_nat_do_registers (obfd, inferior_ptid,
- note_data, note_size);
- }
- else
- {
- note_data = thread_args.note_data;
- }
+ gdb_assert (thread_args.num_notes != 0);
+ note_data = thread_args.note_data;
auxv_len = target_read_alloc (¤t_target, TARGET_OBJECT_AUXV,
NULL, &auxv);
return t;
}
-/* Controls if async mode is permitted. */
-static int linux_async_permitted = 0;
-
-/* The set command writes to this variable. If the inferior is
- executing, linux_nat_async_permitted is *not* updated. */
-static int linux_async_permitted_1 = 0;
-
-static void
-set_maintenance_linux_async_permitted (char *args, int from_tty,
- struct cmd_list_element *c)
-{
- if (target_has_execution)
- {
- linux_async_permitted_1 = linux_async_permitted;
- error (_("Cannot change this setting while the inferior is running."));
- }
-
- linux_async_permitted = linux_async_permitted_1;
- linux_nat_set_async_mode (linux_async_permitted);
-}
-
-static void
-show_maintenance_linux_async_permitted (struct ui_file *file, int from_tty,
- struct cmd_list_element *c, const char *value)
-{
- fprintf_filtered (file, _("\
-Controlling the GNU/Linux inferior in asynchronous mode is %s.\n"),
- value);
-}
-
/* target_is_async_p implementation. */
static int
linux_nat_is_async_p (void)
{
/* NOTE: palves 2008-03-21: We're only async when the user requests
- it explicitly with the "maintenance set linux-async" command.
+ it explicitly with the "maintenance set target-async" command.
Someday, linux will always be async. */
- if (!linux_async_permitted)
+ if (!target_async_permitted)
return 0;
return 1;
linux_nat_can_async_p (void)
{
/* NOTE: palves 2008-03-21: We're only async when the user requests
- it explicitly with the "maintenance set linux-async" command.
+ it explicitly with the "maintenance set target-async" command.
Someday, linux will always be async. */
- if (!linux_async_permitted)
+ if (!target_async_permitted)
return 0;
/* See target.h/target_async_mask. */
return linux_nat_async_mask_value;
}
+static int
+linux_nat_supports_non_stop (void)
+{
+ return 1;
+}
+
/* target_async_mask implementation. */
static int
{
int status, options, pid;
- if (!linux_nat_async_enabled
+ if (!target_async_permitted
|| linux_nat_async_events_state != sigchld_async)
internal_error (__FILE__, __LINE__,
"get_pending_events called with async masked");
linux_nat_async (void (*callback) (enum inferior_event_type event_type,
void *context), void *context)
{
- if (linux_nat_async_mask_value == 0 || !linux_nat_async_enabled)
+ if (linux_nat_async_mask_value == 0 || !target_async_permitted)
internal_error (__FILE__, __LINE__,
"Calling target_async when async is masked");
return;
}
-/* Enable/Disable async mode. */
-
-static void
-linux_nat_set_async_mode (int on)
-{
- if (linux_nat_async_enabled != on)
- {
- if (on)
- {
- gdb_assert (waitpid_queue == NULL);
- if (pipe (linux_nat_event_pipe) == -1)
- internal_error (__FILE__, __LINE__,
- "creating event pipe failed.");
- fcntl (linux_nat_event_pipe[0], F_SETFL, O_NONBLOCK);
- fcntl (linux_nat_event_pipe[1], F_SETFL, O_NONBLOCK);
- }
- else
- {
- drain_queued_events (-1);
- linux_nat_num_queued_events = 0;
- close (linux_nat_event_pipe[0]);
- close (linux_nat_event_pipe[1]);
- linux_nat_event_pipe[0] = linux_nat_event_pipe[1] = -1;
-
- }
- }
- linux_nat_async_enabled = on;
-}
-
static int
send_sigint_callback (struct lwp_info *lp, void *data)
{
t->to_can_async_p = linux_nat_can_async_p;
t->to_is_async_p = linux_nat_is_async_p;
+ t->to_supports_non_stop = linux_nat_supports_non_stop;
t->to_async = linux_nat_async;
t->to_async_mask = linux_nat_async_mask;
t->to_terminal_inferior = linux_nat_terminal_inferior;
return &lp->siginfo;
}
+/* Enable/Disable async mode. */
+
+static void
+linux_nat_setup_async (void)
+{
+ if (pipe (linux_nat_event_pipe) == -1)
+ internal_error (__FILE__, __LINE__,
+ "creating event pipe failed.");
+ fcntl (linux_nat_event_pipe[0], F_SETFL, O_NONBLOCK);
+ fcntl (linux_nat_event_pipe[1], F_SETFL, O_NONBLOCK);
+}
+
void
_initialize_linux_nat (void)
{
show_debug_linux_nat_async,
&setdebuglist, &showdebuglist);
- add_setshow_boolean_cmd ("linux-async", class_maintenance,
- &linux_async_permitted_1, _("\
-Set whether gdb controls the GNU/Linux inferior in asynchronous mode."), _("\
-Show whether gdb controls the GNU/Linux inferior in asynchronous mode."), _("\
-Tells gdb whether to control the GNU/Linux inferior in asynchronous mode."),
- set_maintenance_linux_async_permitted,
- show_maintenance_linux_async_permitted,
- &maintenance_set_cmdlist,
- &maintenance_show_cmdlist);
-
/* Get the default SIGCHLD action. Used while forking an inferior
(see linux_nat_create_inferior/linux_nat_async_events). */
sigaction (SIGCHLD, NULL, &sigchld_default_action);
sigemptyset (&async_sigchld_action.sa_mask);
async_sigchld_action.sa_flags = SA_RESTART;
- /* Install the default mode. */
- linux_nat_set_async_mode (linux_async_permitted);
+ linux_nat_setup_async ();
add_setshow_boolean_cmd ("disable-randomization", class_support,
&disable_randomization, _("\