2013-08-19 16:54:11 +00:00
|
|
|
/* Target waitstatus definitions and prototypes.
|
2013-07-24 16:20:12 +00:00
|
|
|
|
2016-01-01 04:33:14 +00:00
|
|
|
Copyright (C) 1990-2016 Free Software Foundation, Inc.
|
2013-07-24 16:20:12 +00:00
|
|
|
|
|
|
|
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/>. */
|
|
|
|
|
2013-08-19 16:54:11 +00:00
|
|
|
#ifndef WAITSTATUS_H
|
|
|
|
#define WAITSTATUS_H
|
2013-07-24 16:20:12 +00:00
|
|
|
|
|
|
|
#include "gdb_signals.h"
|
|
|
|
|
|
|
|
/* Stuff for target_wait. */
|
|
|
|
|
|
|
|
/* Generally, what has the program done? */
|
|
|
|
enum target_waitkind
|
|
|
|
{
|
|
|
|
/* The program has exited. The exit status is in value.integer. */
|
|
|
|
TARGET_WAITKIND_EXITED,
|
|
|
|
|
|
|
|
/* The program has stopped with a signal. Which signal is in
|
|
|
|
value.sig. */
|
|
|
|
TARGET_WAITKIND_STOPPED,
|
|
|
|
|
|
|
|
/* The program has terminated with a signal. Which signal is in
|
|
|
|
value.sig. */
|
|
|
|
TARGET_WAITKIND_SIGNALLED,
|
|
|
|
|
2013-08-19 16:54:11 +00:00
|
|
|
/* The program is letting us know that it dynamically loaded
|
|
|
|
something (e.g. it called load(2) on AIX). */
|
2013-07-24 16:20:12 +00:00
|
|
|
TARGET_WAITKIND_LOADED,
|
|
|
|
|
|
|
|
/* The program has forked. A "related" process' PTID is in
|
|
|
|
value.related_pid. I.e., if the child forks, value.related_pid
|
|
|
|
is the parent's ID. */
|
|
|
|
TARGET_WAITKIND_FORKED,
|
|
|
|
|
|
|
|
/* The program has vforked. A "related" process's PTID is in
|
|
|
|
value.related_pid. */
|
|
|
|
TARGET_WAITKIND_VFORKED,
|
|
|
|
|
|
|
|
/* The program has exec'ed a new executable file. The new file's
|
|
|
|
pathname is pointed to by value.execd_pathname. */
|
|
|
|
TARGET_WAITKIND_EXECD,
|
|
|
|
|
|
|
|
/* The program had previously vforked, and now the child is done
|
|
|
|
with the shared memory region, because it exec'ed or exited.
|
|
|
|
Note that the event is reported to the vfork parent. This is
|
|
|
|
only used if GDB did not stay attached to the vfork child,
|
|
|
|
otherwise, a TARGET_WAITKIND_EXECD or
|
|
|
|
TARGET_WAITKIND_EXIT|SIGNALLED event associated with the child
|
|
|
|
has the same effect. */
|
|
|
|
TARGET_WAITKIND_VFORK_DONE,
|
|
|
|
|
|
|
|
/* The program has entered or returned from a system call. On
|
|
|
|
HP-UX, this is used in the hardware watchpoint implementation.
|
2013-08-19 16:54:11 +00:00
|
|
|
The syscall's unique integer ID number is in
|
|
|
|
value.syscall_id. */
|
2013-07-24 16:20:12 +00:00
|
|
|
TARGET_WAITKIND_SYSCALL_ENTRY,
|
|
|
|
TARGET_WAITKIND_SYSCALL_RETURN,
|
|
|
|
|
2013-08-19 16:54:11 +00:00
|
|
|
/* Nothing happened, but we stopped anyway. This perhaps should
|
|
|
|
be handled within target_wait, but I'm not sure target_wait
|
|
|
|
should be resuming the inferior. */
|
2013-07-24 16:20:12 +00:00
|
|
|
TARGET_WAITKIND_SPURIOUS,
|
|
|
|
|
|
|
|
/* An event has occured, but we should wait again.
|
|
|
|
Remote_async_wait() returns this when there is an event
|
|
|
|
on the inferior, but the rest of the world is not interested in
|
|
|
|
it. The inferior has not stopped, but has just sent some output
|
|
|
|
to the console, for instance. In this case, we want to go back
|
|
|
|
to the event loop and wait there for another event from the
|
|
|
|
inferior, rather than being stuck in the remote_async_wait()
|
2013-10-17 10:21:37 +00:00
|
|
|
function. This way the event loop is responsive to other events,
|
2013-07-24 16:20:12 +00:00
|
|
|
like for instance the user typing. */
|
|
|
|
TARGET_WAITKIND_IGNORE,
|
|
|
|
|
|
|
|
/* The target has run out of history information,
|
|
|
|
and cannot run backward any further. */
|
|
|
|
TARGET_WAITKIND_NO_HISTORY,
|
|
|
|
|
|
|
|
/* There are no resumed children left in the program. */
|
Remote thread create/exit events
When testing with "maint set target-non-stop on", a few
threading-related tests expose an issue that requires new RSP packets.
Say there are 3 threads running, 1-3. If GDB tries to stop thread 1,
2 and 3, and then waits for their stops, but meanwhile say, thread 2
exits, GDB hangs forever waiting for a stop for thread 2 that won't
ever happen.
This patch fixes the issue by adding support for thread exit events to
the protocol. However, we don't want these always enabled, as they're
useless most of the time, and would slow down remote debugging. So I
made it so that GDB can enable/disable them, and then made gdb do that
around the cases that need it, which currently is only
infrun.c:stop_all_threads.
In turn, if we have thread exit events, then the extra "thread x
exited" traffic slows down attach-many-short-lived-threads.exp enough
that gdb has trouble keeping up with new threads that are spawned
while gdb tries to stop existing ones. To fix that I added support
for the counterpart thread created events too. Enabling those when we
try to stop threads ensures that new threads never get a chance to
themselves start new threads, killing the race.
gdb/doc/ChangeLog:
2015-11-30 Pedro Alves <palves@redhat.com>
* gdb.texinfo (Remote Configuration): List "set/show remote
thread-events" command in configuration table.
(Stop Reply Packets): Document "T05 create" stop
reason and 'w' stop reply.
(General Query Packets): Document QThreadEvents packet. Document
QThreadEvents qSupported feature.
gdb/gdbserver/ChangeLog:
2015-11-30 Pedro Alves <palves@redhat.com>
* linux-low.c (handle_extended_wait): Assert that the LWP's
waitstatus is TARGET_WAITKIND_IGNORE. If GDB wants to hear about
thread create events, leave the new child's status pending.
(linux_low_filter_event): If GDB wants to hear about thread exit
events, leave the LWP marked dead and don't delete it.
(linux_wait_for_event_filtered): Don't check for thread exit.
(filter_exit_event): New function.
(linux_wait_1): Use it, when returning an exit event.
(linux_resume_one_lwp_throw): Assert that the LWP's
waitstatus is TARGET_WAITKIND_IGNORE.
* remote-utils.c (prepare_resume_reply): Handle
TARGET_WAITKIND_THREAD_CREATED and TARGET_WAITKIND_THREAD_EXITED.
* server.c (report_thread_events): New global.
(handle_general_set): Handle QThreadEvents.
(handle_query) <qSupported>: Handle and report QThreadEvents+;
(handle_target_event): Handle TARGET_WAITKIND_THREAD_CREATED and
TARGET_WAITKIND_THREAD_EXITED.
* server.h (report_thread_events): Declare.
gdb/ChangeLog:
2015-11-30 Pedro Alves <palves@redhat.com>
* NEWS (New commands): Mention "set/show remote thread-events"
commands.
(New remote packets): Mention thread created/exited stop reasons
and QThreadEvents packet.
* infrun.c (disable_thread_events): New function.
(stop_all_threads): Disable/enable thread create/exit events.
Handle TARGET_WAITKIND_THREAD_EXITED.
(handle_inferior_event_1): Handle TARGET_WAITKIND_THREAD_CREATED
and TARGET_WAITKIND_THREAD_EXITED.
* remote.c (remove_child_of_pending_fork): Also remove threads of
threads that have TARGET_WAITKIND_THREAD_EXITED events.
(remote_parse_stop_reply): Handle "create" magic register. Handle
'w' stop reply.
(initialize_remote): Install remote_thread_events as
to_thread_events target hook.
(remote_thread_events): New function.
* target-delegates.c: Regenerate.
* target.c (target_thread_events): New function.
* target.h (struct target_ops) <to_thread_events>: New field.
(target_thread_events): Declare.
* target/waitstatus.c (target_waitstatus_to_string): Handle
TARGET_WAITKIND_THREAD_CREATED and TARGET_WAITKIND_THREAD_EXITED.
* target/waitstatus.h (enum target_waitkind)
<TARGET_WAITKIND_THREAD_CREATED, TARGET_WAITKIND_THREAD_EXITED):
New values.
2015-11-30 16:05:21 +00:00
|
|
|
TARGET_WAITKIND_NO_RESUMED,
|
|
|
|
|
|
|
|
/* The thread was created. */
|
|
|
|
TARGET_WAITKIND_THREAD_CREATED,
|
|
|
|
|
|
|
|
/* The thread has exited. The exit status is in value.integer. */
|
|
|
|
TARGET_WAITKIND_THREAD_EXITED,
|
2013-07-24 16:20:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct target_waitstatus
|
|
|
|
{
|
|
|
|
enum target_waitkind kind;
|
|
|
|
|
|
|
|
/* Additional information about the event. */
|
|
|
|
union
|
|
|
|
{
|
|
|
|
/* Exit status */
|
|
|
|
int integer;
|
|
|
|
/* Signal number */
|
|
|
|
enum gdb_signal sig;
|
|
|
|
/* Forked child pid */
|
|
|
|
ptid_t related_pid;
|
|
|
|
/* execd pathname */
|
|
|
|
char *execd_pathname;
|
|
|
|
/* Syscall number */
|
|
|
|
int syscall_number;
|
|
|
|
} value;
|
|
|
|
};
|
|
|
|
|
2015-03-04 20:41:15 +00:00
|
|
|
/* Extended reasons that can explain why a target/thread stopped for a
|
|
|
|
trap signal. */
|
|
|
|
|
|
|
|
enum target_stop_reason
|
|
|
|
{
|
|
|
|
/* Either not stopped, or stopped for a reason that doesn't require
|
|
|
|
special tracking. */
|
|
|
|
TARGET_STOPPED_BY_NO_REASON,
|
|
|
|
|
|
|
|
/* Stopped by a software breakpoint. */
|
|
|
|
TARGET_STOPPED_BY_SW_BREAKPOINT,
|
|
|
|
|
|
|
|
/* Stopped by a hardware breakpoint. */
|
|
|
|
TARGET_STOPPED_BY_HW_BREAKPOINT,
|
|
|
|
|
|
|
|
/* Stopped by a watchpoint. */
|
gdbserver: Fix non-stop / fork / step-over issues
Ref: https://sourceware.org/ml/gdb-patches/2015-07/msg00868.html
This adds a test that has a multithreaded program have several threads
continuously fork, while another thread continuously steps over a
breakpoint.
This exposes several intertwined issues, which this patch addresses:
- When we're stopping and suspending threads, some thread may fork,
and we missed setting its suspend count to 1, like we do when a new
clone/thread is detected. When we next unsuspend threads, the fork
child's suspend count goes below 0, which is bogus and fails an
assertion.
- If a step-over is cancelled because a signal arrives, but then gdb
is not interested in the signal, we pass the signal straight back
to the inferior. However, we miss that we need to re-increment the
suspend counts of all other threads that had been paused for the
step-over. As a result, other threads indefinitely end up stuck
stopped.
- If a detach request comes in just while gdbserver is handling a
step-over (in the test at hand, this is GDB detaching the fork
child), gdbserver internal errors in stabilize_thread's helpers,
which assert that all thread's suspend counts are 0 (otherwise we
wouldn't be able to move threads out of the jump pads). The
suspend counts aren't 0 while a step-over is in progress, because
all threads but the one stepping past the breakpoint must remain
paused until the step-over finishes and the breakpoint can be
reinserted.
- Occasionally, we see "BAD - reinserting but not stepping." being
output (from within linux_resume_one_lwp_throw). That was because
GDB pokes memory while gdbserver is busy with a step-over, and that
suspends threads, and then re-resumes them with proceed_one_lwp,
which missed another reason to tell linux_resume_one_lwp that the
thread should be set back to stepping.
- In a couple places, we were resuming threads that are meant to be
suspended. E.g., when a vCont;c/s request for thread B comes in
just while gdbserver is stepping thread A past a breakpoint. The
resume for thread B must be deferred until the step-over finishes.
- The test runs with both "set detach-on-fork" on and off. When off,
it exercises the case of GDB detaching the fork child explicitly.
When on, it exercises the case of gdb resuming the child
explicitly. In the "off" case, gdb seems to exponentially become
slower as new inferiors are created. This is _very_ noticeable as
with only 100 inferiors gdb is crawling already, which makes the
test take quite a bit to run. For that reason, I've disabled the
"off" variant for now.
gdb/ChangeLog:
2015-08-06 Pedro Alves <palves@redhat.com>
* target/waitstatus.h (enum target_stop_reason)
<TARGET_STOPPED_BY_SINGLE_STEP>: New value.
gdb/gdbserver/ChangeLog:
2015-08-06 Pedro Alves <palves@redhat.com>
* linux-low.c (handle_extended_wait): Set the fork child's suspend
count if stopping and suspending threads.
(check_stopped_by_breakpoint): If stopped by trace, set the LWP's
stop reason to TARGET_STOPPED_BY_SINGLE_STEP.
(linux_detach): Complete an ongoing step-over.
(lwp_suspended_inc, lwp_suspended_decr): New functions. Use
throughout.
(resume_stopped_resumed_lwps): Don't resume a suspended thread.
(linux_wait_1): If passing a signal to the inferior after
finishing a step-over, unsuspend and re-resume all lwps. If we
see a single-step event but the thread should be continuing, don't
pass the trap to gdb.
(stuck_in_jump_pad_callback, move_out_of_jump_pad_callback): Use
internal_error instead of gdb_assert.
(enqueue_pending_signal): New function.
(check_ptrace_stopped_lwp_gone): Add debug output.
(start_step_over): Use internal_error instead of gdb_assert.
(complete_ongoing_step_over): New function.
(linux_resume_one_thread): Don't resume a suspended thread.
(proceed_one_lwp): If the LWP is stepping over a breakpoint, reset
it stepping.
gdb/testsuite/ChangeLog:
2015-08-06 Pedro Alves <palves@redhat.com>
* gdb.threads/forking-threads-plus-breakpoint.exp: New file.
* gdb.threads/forking-threads-plus-breakpoint.c: New file.
2015-08-06 09:30:18 +00:00
|
|
|
TARGET_STOPPED_BY_WATCHPOINT,
|
|
|
|
|
|
|
|
/* Stopped by a single step finishing. */
|
|
|
|
TARGET_STOPPED_BY_SINGLE_STEP
|
2015-03-04 20:41:15 +00:00
|
|
|
};
|
|
|
|
|
2013-07-24 16:20:12 +00:00
|
|
|
/* Prototypes */
|
|
|
|
|
|
|
|
/* 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 *);
|
|
|
|
|
2013-08-19 16:54:11 +00:00
|
|
|
#endif /* WAITSTATUS_H */
|