* target.c (target_wait): Add `options' argument. Adjust.
(struct target_ops) <to_wait>: Add `options' argument.
(target_wait): Add `options' argument.
* infrun.c (wait_for_inferior): Pass 0 as options to
target_wait (blocking wait).
(fetch_inferior_event): Pass TARGET_WNOHANG as options to
target_wait.
* fork-child.c (startup_inferior): Pass 0 as options to
target_wait (blocking wait).
* linux-nat.c (linux_nat_create_inferior): Remove async masking.
(linux_nat_wait_1): Add `target_options' argument. Use it instead
of checking on target_can_async_p.
(linux_nat_wait): Add `target_options' argument. Adjust.
* remote.c (remote_wait_ns): Add `options' argument. Adjust to
check on TARGET_WNOWAIT instead of checking on remote_is_async_p.
(remote_wait_as): Add `options' argument. Adjust to check on
TARGET_WNOWAIT instead of checking on remote_is_async_p. If doing
a blocking wait, keep waiting until an interesting event comes
out.
(remote_wait): Add `options' argument. Don't loop here if the
target is in async mode, and a blocking wait has been requested.
* top.c (deprecated_target_wait_hook): Add `options' argument.
* linux-thread-db.c (thread_db_wait): Add `options' argument, and
pass it down to the layer beneath.
* inf-ptrace.c (inf_ptrace_wait): Add `options' argument.
* record.c (record_beneath_to_wait): Add `options' argument.
(record_wait): Add `options' argument, and pass it down to the
layer beneath.
* bsd-uthread.c (bsd_uthread_wait): Add `options' argument.
* darwin-nat.c (darwin_wait): Likewise.
* defs.h (deprecated_target_wait_hook): Likewise.
* gnu-nat.c (gnu_wait): Add `options' argument.
* go32-nat.c (go32_wait): Likewise.
* hpux-thread.c (hpux_thread_wait): Add `options' argument, and
pass it down to the layer beneath.
* inf-ttrace.c (inf_ttrace_wait): Add `options' argument.
* monitor.c (monitor_wait): Likewise.
* nto-procfs.c (procfs_wait): Likewise.
* remote-mips.c (mips_wait): Add `options' argument.
* remote-sim.c (gdbsim_wait): Likewise.
* rs6000-nat.c (rs6000_wait): Add `options' argument.
* sol-thread.c (sol_thread_wait): Add `options' argument, and pass
it down to the layer beneath.
* spu-linux-nat.c (spu_child_wait): Add `options' argument.
* windows-nat.c (windows_wait): Likewise.
* tui/tui-hooks.c (tui_target_wait_hook): Likewise. Adjust.
+2009-05-21 Pedro Alves <pedro@codesourcery.com>
+
+ * target.h (TARGET_WNOHANG): New.
+ * target.c (target_wait): Add `options' argument. Adjust.
+ (struct target_ops) <to_wait>: Add `options' argument.
+ (target_wait): Add `options' argument.
+ * infrun.c (wait_for_inferior): Pass 0 as options to
+ target_wait (blocking wait).
+ (fetch_inferior_event): Pass TARGET_WNOHANG as options to
+ target_wait.
+ * fork-child.c (startup_inferior): Pass 0 as options to
+ target_wait (blocking wait).
+ * linux-nat.c (linux_nat_create_inferior): Remove async masking.
+ (linux_nat_wait_1): Add `target_options' argument. Use it instead
+ of checking on target_can_async_p.
+ (linux_nat_wait): Add `target_options' argument. Adjust.
+ * remote.c (remote_wait_ns): Add `options' argument. Adjust to
+ check on TARGET_WNOWAIT instead of checking on remote_is_async_p.
+ (remote_wait_as): Add `options' argument. Adjust to check on
+ TARGET_WNOWAIT instead of checking on remote_is_async_p. If doing
+ a blocking wait, keep waiting until an interesting event comes
+ out.
+ (remote_wait): Add `options' argument. Don't loop here if the
+ target is in async mode, and a blocking wait has been requested.
+
+ * top.c (deprecated_target_wait_hook): Add `options' argument.
+ * linux-thread-db.c (thread_db_wait): Add `options' argument, and
+ pass it down to the layer beneath.
+ * inf-ptrace.c (inf_ptrace_wait): Add `options' argument.
+ * record.c (record_beneath_to_wait): Add `options' argument.
+ (record_wait): Add `options' argument, and pass it down to the
+ layer beneath.
+ * bsd-uthread.c (bsd_uthread_wait): Add `options' argument.
+ * darwin-nat.c (darwin_wait): Likewise.
+ * defs.h (deprecated_target_wait_hook): Likewise.
+ * gnu-nat.c (gnu_wait): Add `options' argument.
+ * go32-nat.c (go32_wait): Likewise.
+ * hpux-thread.c (hpux_thread_wait): Add `options' argument, and
+ pass it down to the layer beneath.
+ * inf-ttrace.c (inf_ttrace_wait): Add `options' argument.
+ * monitor.c (monitor_wait): Likewise.
+ * nto-procfs.c (procfs_wait): Likewise.
+ * remote-mips.c (mips_wait): Add `options' argument.
+ * remote-sim.c (gdbsim_wait): Likewise.
+ * rs6000-nat.c (rs6000_wait): Add `options' argument.
+ * sol-thread.c (sol_thread_wait): Add `options' argument, and pass
+ it down to the layer beneath.
+ * spu-linux-nat.c (spu_child_wait): Add `options' argument.
+ * windows-nat.c (windows_wait): Likewise.
+ * tui/tui-hooks.c (tui_target_wait_hook): Likewise. Adjust.
+
2009-05-21 Pedro Alves <pedro@codesourcery.com>
* mi/mi-interp.c (mi_on_resume): Account for whole process
static ptid_t
bsd_uthread_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *status)
+ ptid_t ptid, struct target_waitstatus *status, int options)
{
CORE_ADDR addr;
struct target_ops *beneath = find_target_beneath (ops);
/* Pass the request to the layer beneath. */
- ptid = beneath->to_wait (beneath, ptid, status);
+ ptid = beneath->to_wait (beneath, ptid, status, options);
/* If the process is no longer alive, there's no point in figuring
out the thread ID. It will fail anyway. */
static ptid_t
darwin_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *status)
+ ptid_t ptid, struct target_waitstatus *status, int options)
{
kern_return_t kret;
mach_msg_header_t *hdr = &msgin.hdr;
extern void (*deprecated_memory_changed_hook) (CORE_ADDR addr, int len);
extern void (*deprecated_context_hook) (int);
extern ptid_t (*deprecated_target_wait_hook) (ptid_t ptid,
- struct target_waitstatus * status);
+ struct target_waitstatus *status,
+ int options);
extern void (*deprecated_attach_hook) (void);
extern void (*deprecated_detach_hook) (void);
struct target_waitstatus ws;
memset (&ws, 0, sizeof (ws));
- event_ptid = target_wait (resume_ptid, &ws);
+ event_ptid = target_wait (resume_ptid, &ws, 0);
if (ws.kind == TARGET_WAITKIND_IGNORE)
/* The inferior didn't really stop, keep waiting. */
/* Wait for something to happen in the inferior, returning what in STATUS. */
static ptid_t
gnu_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *status)
+ ptid_t ptid, struct target_waitstatus *status, int options)
{
struct msg
{
static ptid_t
go32_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *status)
+ ptid_t ptid, struct target_waitstatus *status, int options)
{
int i;
unsigned char saved_opcode;
static ptid_t
hpux_thread_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *ourstatus)
+ ptid_t ptid, struct target_waitstatus *ourstatus, int options)
{
ptid_t rtnval;
struct cleanup *old_chain;
ptid = main_ptid;
rtnval = deprecated_child_ops.to_wait (&deprecated_child_ops,
- ptid, ourstatus);
+ ptid, ourstatus, options);
rtnval = find_active_thread ();
static ptid_t
inf_ptrace_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *ourstatus)
+ ptid_t ptid, struct target_waitstatus *ourstatus, int options)
{
pid_t pid;
int status, save_errno;
static ptid_t
inf_ttrace_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *ourstatus)
+ ptid_t ptid, struct target_waitstatus *ourstatus, int options)
{
pid_t pid = ptid_get_pid (ptid);
lwpid_t lwpid = ptid_get_lwp (ptid);
struct cleanup *old_chain;
if (deprecated_target_wait_hook)
- ecs->ptid = deprecated_target_wait_hook (waiton_ptid, &ecs->ws);
+ ecs->ptid = deprecated_target_wait_hook (waiton_ptid, &ecs->ws, 0);
else
- ecs->ptid = target_wait (waiton_ptid, &ecs->ws);
+ ecs->ptid = target_wait (waiton_ptid, &ecs->ws, 0);
if (debug_infrun)
print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
if (deprecated_target_wait_hook)
ecs->ptid =
- deprecated_target_wait_hook (waiton_ptid, &ecs->ws);
+ deprecated_target_wait_hook (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
else
- ecs->ptid = target_wait (waiton_ptid, &ecs->ws);
+ ecs->ptid = target_wait (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
if (debug_infrun)
print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
char *exec_file, char *allargs, char **env,
int from_tty)
{
- int saved_async = 0;
#ifdef HAVE_PERSONALITY
int personality_orig = 0, personality_set = 0;
#endif /* HAVE_PERSONALITY */
/* The fork_child mechanism is synchronous and calls target_wait, so
we have to mask the async mode. */
- if (target_can_async_p ())
- /* Mask async mode. Creating a child requires a loop calling
- wait_for_inferior currently. */
- saved_async = linux_nat_async_mask (0);
-
#ifdef HAVE_PERSONALITY
if (disable_randomization)
{
safe_strerror (errno));
}
#endif /* HAVE_PERSONALITY */
-
- if (saved_async)
- linux_nat_async_mask (saved_async);
}
static void
static ptid_t
linux_nat_wait_1 (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *ourstatus)
+ ptid_t ptid, struct target_waitstatus *ourstatus,
+ int target_options)
{
static sigset_t prev_mask;
struct lwp_info *lp = NULL;
set_sigint_trap ();
}
- if (target_can_async_p ())
- options |= WNOHANG; /* In async mode, don't block. */
+ /* Translate generic target_wait options into waitpid options. */
+ if (target_options & TARGET_WNOHANG)
+ options |= WNOHANG;
while (lp == NULL)
{
In sync mode, suspend waiting for a SIGCHLD signal. */
if (options & __WCLONE)
{
- if (target_can_async_p ())
+ if (target_options & TARGET_WNOHANG)
{
/* No interesting event. */
ourstatus->kind = TARGET_WAITKIND_IGNORE;
static ptid_t
linux_nat_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *ourstatus)
+ ptid_t ptid, struct target_waitstatus *ourstatus,
+ int target_options)
{
ptid_t event_ptid;
if (target_can_async_p ())
async_file_flush ();
- event_ptid = linux_nat_wait_1 (ops, ptid, ourstatus);
+ event_ptid = linux_nat_wait_1 (ops, ptid, ourstatus, target_options);
/* If we requested any event, and something came out, assume there
may be more. If we requested a specific lwp or process, also
static ptid_t
thread_db_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *ourstatus)
+ ptid_t ptid, struct target_waitstatus *ourstatus,
+ int options)
{
struct thread_db_info *info;
struct target_ops *beneath = find_target_beneath (ops);
- ptid = beneath->to_wait (beneath, ptid, ourstatus);
+ ptid = beneath->to_wait (beneath, ptid, ourstatus, options);
if (ourstatus->kind == TARGET_WAITKIND_IGNORE)
return ptid;
static ptid_t
monitor_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *status)
+ ptid_t ptid, struct target_waitstatus *status, int options)
{
int old_timeout = timeout;
char buf[TARGET_BUF_SIZE];
static ptid_t
procfs_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *ourstatus)
+ ptid_t ptid, struct target_waitstatus *ourstatus, int options)
{
sigset_t set;
siginfo_t info;
enum target_signal);
static struct target_ops *record_beneath_to_wait_ops;
static ptid_t (*record_beneath_to_wait) (struct target_ops *, ptid_t,
- struct target_waitstatus *);
+ struct target_waitstatus *,
+ int);
static struct target_ops *record_beneath_to_store_registers_ops;
static void (*record_beneath_to_store_registers) (struct target_ops *,
struct regcache *,
static ptid_t
record_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *status)
+ ptid_t ptid, struct target_waitstatus *status,
+ int options)
{
struct cleanup *set_cleanups = record_gdb_operation_disable_set ();
{
/* This is a single step. */
return record_beneath_to_wait (record_beneath_to_wait_ops,
- ptid, status);
+ ptid, status, 0);
}
else
{
while (1)
{
ret = record_beneath_to_wait (record_beneath_to_wait_ops,
- ptid, status);
+ ptid, status, 0);
if (status->kind == TARGET_WAITKIND_STOPPED
&& status->value.sig == TARGET_SIGNAL_TRAP)
static ptid_t
mips_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *status)
+ ptid_t ptid, struct target_waitstatus *status, int options)
{
int rstatus;
int err;
static ptid_t
gdbsim_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *status)
+ ptid_t ptid, struct target_waitstatus *status, int options)
{
static RETSIGTYPE (*prev_sigint) ();
int sigrc = 0;
/* The non-stop mode version of target_wait. */
static ptid_t
-remote_wait_ns (ptid_t ptid, struct target_waitstatus *status)
+remote_wait_ns (ptid_t ptid, struct target_waitstatus *status, int options)
{
struct remote_state *rs = get_remote_state ();
struct remote_arch_state *rsa = get_remote_arch_state ();
if (stop_reply != NULL)
return process_stop_reply (stop_reply, status);
- /* Still no event. If we're in asynchronous mode, then just
+ /* Still no event. If we're just polling for an event, then
return to the event loop. */
- if (remote_is_async_p ())
+ if (options & TARGET_WNOHANG)
{
status->kind = TARGET_WAITKIND_IGNORE;
return minus_one_ptid;
}
- /* Otherwise, asynchronous mode is masked, so do a blocking
- wait. */
+ /* Otherwise do a blocking wait. */
ret = getpkt_or_notif_sane (&rs->buf, &rs->buf_size,
1 /* forever */);
}
STATUS just as `wait' would. */
static ptid_t
-remote_wait_as (ptid_t ptid, struct target_waitstatus *status)
+remote_wait_as (ptid_t ptid, struct target_waitstatus *status, int options)
{
struct remote_state *rs = get_remote_state ();
struct remote_arch_state *rsa = get_remote_arch_state ();
char *buf, *p;
struct stop_reply *stop_reply;
+ again:
+
status->kind = TARGET_WAITKIND_IGNORE;
status->value.integer = 0;
}
if (status->kind == TARGET_WAITKIND_IGNORE)
- /* Nothing interesting happened. */
- return minus_one_ptid;
+ {
+ /* Nothing interesting happened. If we're doing a non-blocking
+ poll, we're done. Otherwise, go back to waiting. */
+ if (options & TARGET_WNOHANG)
+ return minus_one_ptid;
+ else
+ goto again;
+ }
else if (status->kind != TARGET_WAITKIND_EXITED
&& status->kind != TARGET_WAITKIND_SIGNALLED)
{
static ptid_t
remote_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *status)
+ ptid_t ptid, struct target_waitstatus *status, int options)
{
ptid_t event_ptid;
if (non_stop)
- event_ptid = remote_wait_ns (ptid, status);
+ event_ptid = remote_wait_ns (ptid, status, options);
else
- {
- /* In synchronous mode, keep waiting until the target stops. In
- asynchronous mode, always return to the event loop. */
-
- do
- {
- event_ptid = remote_wait_as (ptid, status);
- }
- while (status->kind == TARGET_WAITKIND_IGNORE
- && !target_can_async_p ());
- }
+ event_ptid = remote_wait_as (ptid, status, options);
if (target_can_async_p ())
{
static ptid_t
rs6000_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *ourstatus)
+ ptid_t ptid, struct target_waitstatus *ourstatus, int options)
{
pid_t pid;
int status, save_errno;
static ptid_t
sol_thread_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *ourstatus)
+ ptid_t ptid, struct target_waitstatus *ourstatus, int options)
{
ptid_t rtnval;
ptid_t save_ptid;
GET_THREAD (save_ptid));
}
- rtnval = beneath->to_wait (beneath, ptid, ourstatus);
+ rtnval = beneath->to_wait (beneath, ptid, ourstatus, options);
if (ourstatus->kind != TARGET_WAITKIND_EXITED)
{
minus_one_ptid in case of error; store status into *OURSTATUS. */
static ptid_t
spu_child_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *ourstatus)
+ ptid_t ptid, struct target_waitstatus *ourstatus, int options)
{
int save_errno;
int status;
}
ptid_t
-target_wait (ptid_t ptid, struct target_waitstatus *status)
+target_wait (ptid_t ptid, struct target_waitstatus *status, int options)
{
struct target_ops *t;
{
if (t->to_wait != NULL)
{
- ptid_t retval = (*t->to_wait) (t, ptid, status);
+ ptid_t retval = (*t->to_wait) (t, ptid, status, options);
if (targetdebug)
{
value;
};
+/* Options that can be passed to target_wait. */
+
+/* Return immediately if there's no event already queued. If this
+ options is not requested, target_wait blocks waiting for an
+ event. */
+#define TARGET_WNOHANG 1
+
/* Return a pretty printed form of target_waitstatus.
Space for the result is malloc'd, caller must free. */
extern char *target_waitstatus_to_string (const struct target_waitstatus *);
void (*to_disconnect) (struct target_ops *, char *, int);
void (*to_resume) (struct target_ops *, ptid_t, int, enum target_signal);
ptid_t (*to_wait) (struct target_ops *,
- ptid_t, struct target_waitstatus *);
+ ptid_t, struct target_waitstatus *, int);
void (*to_fetch_registers) (struct target_ops *, struct regcache *, int);
void (*to_store_registers) (struct target_ops *, struct regcache *, int);
void (*to_prepare_to_store) (struct regcache *);
_NOT_ OK to throw_exception() out of target_wait() without popping
the debugging target from the stack; GDB isn't prepared to get back
to the prompt with a debugging target but without the frame cache,
- stop_pc, etc., set up. */
+ stop_pc, etc., set up. OPTIONS is a bitwise OR of TARGET_W*
+ options. */
-extern ptid_t target_wait (ptid_t ptid, struct target_waitstatus *status);
+extern ptid_t target_wait (ptid_t ptid, struct target_waitstatus *status,
+ int options);
/* Fetch at least register REGNO, or all regs if regno == -1. No result. */
while waiting for target events. */
ptid_t (*deprecated_target_wait_hook) (ptid_t ptid,
- struct target_waitstatus * status);
+ struct target_waitstatus *status,
+ int options);
/* Used by UI as a wrapper around command execution. May do various things
like enabling/disabling buttons, etc... */
Leave curses mode and setup program mode. */
static ptid_t
tui_target_wait_hook (ptid_t pid,
- struct target_waitstatus *status)
+ struct target_waitstatus *status, int options)
{
ptid_t res;
}
#endif
tui_target_has_run = 1;
- res = target_wait (pid, status);
+ res = target_wait (pid, status, options);
if (tui_active)
{
/* Wait for interesting events to occur in the target process. */
static ptid_t
windows_wait (struct target_ops *ops,
- ptid_t ptid, struct target_waitstatus *ourstatus)
+ ptid_t ptid, struct target_waitstatus *ourstatus, int options)
{
int pid = -1;