fa96cb382c
GDBserver currently hangs forever in waitpid if the leader thread exits before other threads, or if all resumed threads exit - e.g., next over a thread exit with sched-locking on. This is exposed by leader-exit.exp. leader-exit.exp is part of a series of tests for a set of related problems. See <http://www.sourceware.org/ml/gdb-patches/2011-10/msg00704.html>: " To recap, on the Linux kernel, ptrace/waitpid don't allow reaping the leader thread until all other threads in the group are reaped. When the leader exits, it goes zombie, but waitpid will not return an exit status until the other threads are gone. This is presently exercised by the gdb.threads/leader-exit.exp test. The fix for that test, in linux-nat.c:wait_lwp, handles the case where we see the leader gone when we're stopping all threads to report an event to some other thread to the core. (...) The latter bit about not blocking if there no resumed threads in the process also applies to some other thread exiting, not just the main thread. E.g., this test starts a thread, and runs to a breakpoint in that thread: ... (gdb) c Continuing. [New Thread 0x7ffff75a4700 (LWP 23397)] [Switching to Thread 0x7ffff75a4700 (LWP 23397)] Breakpoint 2, thread_a (arg=0x0) at ../../../src/gdb/testsuite/gdb.threads/no-unwaited-for-left.c:28 28 return 0; /* break-here */ (gdb) info threads * 2 Thread 0x7ffff75a4700 (LWP 23397) thread_a (arg=0x0) at ../../../src/gdb/testsuite/gdb.threads/no-unwaited-for-left.c:28 1 Thread 0x7ffff7fcb720 (LWP 23391) 0x00007ffff7bc606d in pthread_join (threadid=140737343276800, thread_return=0x0) at pthread_join.c:89 The thread will exit as soon as we resume it. But if we only resume that thread, leaving the rest of the threads stopped: (gdb) set scheduler-locking on (gdb) c Continuing. ^C^C^C^C^C^C^C^C " This patch fixes the issues by implementing TARGET_WAITKIND_NO_RESUMED on GDBserver, similarly to what the patch above did for native Linux GDB. gdb.threads/leader-exit.exp now passes. gdb.threads/no-unwaited-for-left.exp now at least errors out instead of hanging: continue Continuing. warning: Remote failure reply: E.No unwaited-for children left. [Thread 15454] #1 stopped. 0x00000034cf408e60 in pthread_join (threadid=140737353922368, thread_return=0x0) at pthread_join.c:93 93 lll_wait_tid (pd->tid); (gdb) FAIL: gdb.threads/no-unwaited-for-left.exp: continue stops when the main thread exits The gdb.threads/non-ldr-exc-*.exp tests are skipped because GDBserver unfortunately doesn't support fork/exec yet, but I'm confident this fixes the related issues. I'm leaving modeling TARGET_WAITKIND_NO_RESUMED in the RSP for a separate pass. (BTW, in case of error in response to a vCont, it would be better for GDB to query the target for the current thread, or re-select one, instead of assuming current inferior_ptid is still the selected thread.) This implementation is a little different from GDB's, because I'm avoiding bringing in more of this broken use of waitpid(PID) into GDBserver. Specifically, this avoids waitpid(PID) when stopping all threads. There's really no need for wait_for_sigstop to wait for each LWP in turn. Instead, with some refactoring, we make it reuse linux_wait_for_event. gdb/gdbserver/ 2014-02-27 Pedro Alves <palves@redhat.com> PR 12702 * inferiors.h (A_I_NEXT, ALL_INFERIORS_TYPE, ALL_PROCESSES): New macros. * linux-low.c (delete_lwp, handle_extended_wait): Add debug output. (last_thread_of_process_p): Take a PID argument instead of a thread pointer. (linux_wait_for_lwp): Delete. (num_lwps, check_zombie_leaders, not_stopped_callback): New functions. (linux_low_filter_event): New function, party factored out from linux_wait_for_event. (linux_wait_for_event): Rename to ... (linux_wait_for_event_filtered): ... this. Add new filter ptid argument. Partly rewrite. Always use waitpid(-1, WNOHANG) and sigsuspend. Check for zombie leaders. (linux_wait_for_event): Reimplement as wrapper around linux_wait_for_event_filtered. (linux_wait_1): Handle TARGET_WAITKIND_NO_RESUMED. Assume that if a normal or signal exit is seen, it's the whole process exiting. (wait_for_sigstop): No longer a for_each_inferior callback. Rewrite on top of linux_wait_for_event_filtered. (stop_all_lwps): Call wait_for_sigstop directly. * server.c (resume, handle_target_event): Handle TARGET_WAITKIND_NO_RESUMED.
153 lines
4.8 KiB
C
153 lines
4.8 KiB
C
/* Inferior process information for the remote server for GDB.
|
|
Copyright (C) 1993-2014 Free Software Foundation, Inc.
|
|
|
|
This file is part of GDB.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
#ifndef INFERIORS_H
|
|
#define INFERIORS_H
|
|
|
|
/* Generic information for tracking a list of ``inferiors'' - threads,
|
|
processes, etc. */
|
|
struct inferior_list
|
|
{
|
|
struct inferior_list_entry *head;
|
|
struct inferior_list_entry *tail;
|
|
};
|
|
struct inferior_list_entry
|
|
{
|
|
ptid_t id;
|
|
struct inferior_list_entry *next;
|
|
};
|
|
|
|
struct thread_info;
|
|
struct target_desc;
|
|
struct sym_cache;
|
|
struct breakpoint;
|
|
struct raw_breakpoint;
|
|
struct fast_tracepoint_jump;
|
|
struct process_info_private;
|
|
|
|
struct process_info
|
|
{
|
|
/* This must appear first.
|
|
The list iterator functions assume it. */
|
|
struct inferior_list_entry entry;
|
|
|
|
/* Nonzero if this child process was attached rather than
|
|
spawned. */
|
|
int attached;
|
|
|
|
/* True if GDB asked us to detach from this process, but we remained
|
|
attached anyway. */
|
|
int gdb_detached;
|
|
|
|
/* The symbol cache. */
|
|
struct sym_cache *symbol_cache;
|
|
|
|
/* The list of memory breakpoints. */
|
|
struct breakpoint *breakpoints;
|
|
|
|
/* The list of raw memory breakpoints. */
|
|
struct raw_breakpoint *raw_breakpoints;
|
|
|
|
/* The list of installed fast tracepoints. */
|
|
struct fast_tracepoint_jump *fast_tracepoint_jumps;
|
|
|
|
const struct target_desc *tdesc;
|
|
|
|
/* Private target data. */
|
|
struct process_info_private *private;
|
|
};
|
|
|
|
#define ptid_of(inf) ((inf)->entry.id)
|
|
#define pid_of(inf) ptid_get_pid ((inf)->entry.id)
|
|
#define lwpid_of(inf) ptid_get_lwp ((inf)->entry.id)
|
|
|
|
/* Return a pointer to the process that corresponds to the current
|
|
thread (current_inferior). It is an error to call this if there is
|
|
no current thread selected. */
|
|
|
|
struct process_info *current_process (void);
|
|
struct process_info *get_thread_process (struct thread_info *);
|
|
|
|
extern struct inferior_list all_processes;
|
|
|
|
void add_inferior_to_list (struct inferior_list *list,
|
|
struct inferior_list_entry *new_inferior);
|
|
void for_each_inferior (struct inferior_list *list,
|
|
void (*action) (struct inferior_list_entry *));
|
|
|
|
void for_each_inferior_with_data
|
|
(struct inferior_list *list,
|
|
void (*action) (struct inferior_list_entry *, void *),
|
|
void *data);
|
|
|
|
void clear_inferior_list (struct inferior_list *list);
|
|
|
|
int one_inferior_p (struct inferior_list *list);
|
|
|
|
/* Helper for ALL_INFERIORS_TYPE. Gets the next element starting at
|
|
CUR, if CUR is not NULL. */
|
|
#define A_I_NEXT(type, list, cur) \
|
|
((cur) != NULL \
|
|
? (type *) ((struct inferior_list_entry *) cur)->next \
|
|
: NULL)
|
|
|
|
/* Iterate over all inferiors of type TYPE in LIST, open loop
|
|
style. */
|
|
#define ALL_INFERIORS_TYPE(type, list, cur, tmp) \
|
|
for ((cur) = (type *) (list)->head, (tmp) = A_I_NEXT (type, list, cur); \
|
|
(cur) != NULL; \
|
|
(cur) = (tmp), (tmp) = A_I_NEXT (type, list, cur))
|
|
|
|
/* Iterate over all inferiors in LIST, open loop style. */
|
|
#define ALL_INFERIORS(list, cur, tmp) \
|
|
ALL_INFERIORS_TYPE (struct inferior_list_entry, list, cur, tmp)
|
|
|
|
/* Iterate over all processes, open loop style. */
|
|
#define ALL_PROCESSES(cur, tmp) \
|
|
ALL_INFERIORS_TYPE (struct process_info, &all_processes, cur, tmp)
|
|
|
|
extern struct thread_info *current_inferior;
|
|
void remove_inferior (struct inferior_list *list,
|
|
struct inferior_list_entry *entry);
|
|
|
|
struct inferior_list_entry *get_first_inferior (struct inferior_list *list);
|
|
|
|
struct process_info *add_process (int pid, int attached);
|
|
void remove_process (struct process_info *process);
|
|
struct process_info *find_process_pid (int pid);
|
|
int have_started_inferiors_p (void);
|
|
int have_attached_inferiors_p (void);
|
|
|
|
ptid_t thread_to_gdb_id (struct thread_info *);
|
|
ptid_t gdb_id_to_thread_id (ptid_t);
|
|
|
|
void clear_inferiors (void);
|
|
struct inferior_list_entry *find_inferior
|
|
(struct inferior_list *,
|
|
int (*func) (struct inferior_list_entry *,
|
|
void *),
|
|
void *arg);
|
|
struct inferior_list_entry *find_inferior_id (struct inferior_list *list,
|
|
ptid_t id);
|
|
|
|
void *inferior_target_data (struct thread_info *);
|
|
void set_inferior_target_data (struct thread_info *, void *);
|
|
void *inferior_regcache_data (struct thread_info *);
|
|
void set_inferior_regcache_data (struct thread_info *, void *);
|
|
|
|
#endif /* INFERIORS_H */
|