gdb: pass child_ptid and fork kind to target_ops::follow_fork
This is a small cleanup I think would be nice, that I spotted while doing the following patch. gdb/ChangeLog: * target.h (struct target_ops) <follow_fork>: Add ptid and target_waitkind parameters. (target_follow_fork): Likewise. * target.c (default_follow_fork): Likewise. (target_follow_fork): Likewise. * fbsd-nat.h (class fbsd_nat_target) <follow_fork>: Likewise. * fbsd-nat.c (fbsd_nat_target::follow_fork): Likewise. * linux-nat.h (class linux_nat_target) <follow_fork>: Likewise. * linux-nat.c (linux_nat_target::follow_fork): Likewise. * obsd-nat.h (class obsd_nat_target) <follow_fork>: Likewise. * obsd-nat.c (obsd_nat_target::follow_fork): Likewise. * remote.c (class remote_target) <follow_fork>: Likewise. * target-debug.h (target_debug_print_target_waitkind): New. * target-delegates.c: Re-generate. Change-Id: I5421a542f2e19100a22b74cc333d2b235d0de3c8
This commit is contained in:
parent
ff77083572
commit
3a849a3454
12 changed files with 59 additions and 64 deletions
|
@ -1471,12 +1471,12 @@ fbsd_nat_target::create_inferior (const char *exec_file,
|
||||||
the ptid of the followed inferior. */
|
the ptid of the followed inferior. */
|
||||||
|
|
||||||
void
|
void
|
||||||
fbsd_nat_target::follow_fork (bool follow_child, bool detach_fork)
|
fbsd_nat_target::follow_fork (ptid_t child_ptid, target_waitkind fork_kind,
|
||||||
|
bool follow_child, bool detach_fork)
|
||||||
{
|
{
|
||||||
if (!follow_child && detach_fork)
|
if (!follow_child && detach_fork)
|
||||||
{
|
{
|
||||||
struct thread_info *tp = inferior_thread ();
|
pid_t child_pid = child_ptid.pid ();
|
||||||
pid_t child_pid = tp->pending_follow.value.related_pid.pid ();
|
|
||||||
|
|
||||||
/* Breakpoints have already been detached from the child by
|
/* Breakpoints have already been detached from the child by
|
||||||
infrun.c. */
|
infrun.c. */
|
||||||
|
@ -1485,7 +1485,7 @@ fbsd_nat_target::follow_fork (bool follow_child, bool detach_fork)
|
||||||
perror_with_name (("ptrace"));
|
perror_with_name (("ptrace"));
|
||||||
|
|
||||||
#ifndef PTRACE_VFORK
|
#ifndef PTRACE_VFORK
|
||||||
if (tp->pending_follow.kind == TARGET_WAITKIND_VFORKED)
|
if (fork_kind == TARGET_WAITKIND_VFORKED)
|
||||||
{
|
{
|
||||||
/* We can't insert breakpoints until the child process has
|
/* We can't insert breakpoints until the child process has
|
||||||
finished with the shared memory region. The parent
|
finished with the shared memory region. The parent
|
||||||
|
|
|
@ -85,7 +85,7 @@ public:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TDP_RFPPWAIT
|
#ifdef TDP_RFPPWAIT
|
||||||
void follow_fork (bool, bool) override;
|
void follow_fork (ptid_t, target_waitkind, bool, bool) override;
|
||||||
|
|
||||||
int insert_fork_catchpoint (int) override;
|
int insert_fork_catchpoint (int) override;
|
||||||
int remove_fork_catchpoint (int) override;
|
int remove_fork_catchpoint (int) override;
|
||||||
|
|
15
gdb/infrun.c
15
gdb/infrun.c
|
@ -404,13 +404,12 @@ show_follow_fork_mode_string (struct ui_file *file, int from_tty,
|
||||||
static bool
|
static bool
|
||||||
follow_fork_inferior (bool follow_child, bool detach_fork)
|
follow_fork_inferior (bool follow_child, bool detach_fork)
|
||||||
{
|
{
|
||||||
int has_vforked;
|
target_waitkind fork_kind = inferior_thread ()->pending_follow.kind;
|
||||||
ptid_t parent_ptid, child_ptid;
|
gdb_assert (fork_kind == TARGET_WAITKIND_FORKED
|
||||||
|
|| fork_kind == TARGET_WAITKIND_VFORKED);
|
||||||
has_vforked = (inferior_thread ()->pending_follow.kind
|
bool has_vforked = fork_kind == TARGET_WAITKIND_VFORKED;
|
||||||
== TARGET_WAITKIND_VFORKED);
|
ptid_t parent_ptid = inferior_ptid;
|
||||||
parent_ptid = inferior_ptid;
|
ptid_t child_ptid = inferior_thread ()->pending_follow.value.related_pid;
|
||||||
child_ptid = inferior_thread ()->pending_follow.value.related_pid;
|
|
||||||
|
|
||||||
if (has_vforked
|
if (has_vforked
|
||||||
&& !non_stop /* Non-stop always resumes both branches. */
|
&& !non_stop /* Non-stop always resumes both branches. */
|
||||||
|
@ -649,7 +648,7 @@ holding the child stopped. Try \"set detach-on-fork\" or \
|
||||||
switch_to_thread (child_thr);
|
switch_to_thread (child_thr);
|
||||||
}
|
}
|
||||||
|
|
||||||
target_follow_fork (follow_child, detach_fork);
|
target_follow_fork (child_ptid, fork_kind, follow_child, detach_fork);
|
||||||
|
|
||||||
/* If we ended up creating a new inferior, call post_create_inferior to inform
|
/* If we ended up creating a new inferior, call post_create_inferior to inform
|
||||||
the various subcomponents. */
|
the various subcomponents. */
|
||||||
|
|
|
@ -449,24 +449,19 @@ typedef std::unique_ptr<struct lwp_info, lwp_deleter> lwp_info_up;
|
||||||
unchanged. */
|
unchanged. */
|
||||||
|
|
||||||
void
|
void
|
||||||
linux_nat_target::follow_fork (bool follow_child, bool detach_fork)
|
linux_nat_target::follow_fork (ptid_t child_ptid, target_waitkind fork_kind,
|
||||||
|
bool follow_child, bool detach_fork)
|
||||||
{
|
{
|
||||||
if (!follow_child)
|
if (!follow_child)
|
||||||
{
|
{
|
||||||
struct lwp_info *child_lp = NULL;
|
bool has_vforked = fork_kind == TARGET_WAITKIND_VFORKED;
|
||||||
int has_vforked;
|
ptid_t parent_ptid = inferior_ptid;
|
||||||
ptid_t parent_ptid, child_ptid;
|
|
||||||
int parent_pid, child_pid;
|
|
||||||
|
|
||||||
has_vforked = (inferior_thread ()->pending_follow.kind
|
|
||||||
== TARGET_WAITKIND_VFORKED);
|
|
||||||
parent_ptid = inferior_ptid;
|
|
||||||
child_ptid = inferior_thread ()->pending_follow.value.related_pid;
|
child_ptid = inferior_thread ()->pending_follow.value.related_pid;
|
||||||
parent_pid = parent_ptid.lwp ();
|
int parent_pid = parent_ptid.lwp ();
|
||||||
child_pid = child_ptid.lwp ();
|
int child_pid = child_ptid.lwp ();
|
||||||
|
|
||||||
/* We're already attached to the parent, by default. */
|
/* We're already attached to the parent, by default. */
|
||||||
child_lp = add_lwp (child_ptid);
|
lwp_info *child_lp = add_lwp (child_ptid);
|
||||||
child_lp->stopped = 1;
|
child_lp->stopped = 1;
|
||||||
child_lp->last_resume_kind = resume_stop;
|
child_lp->last_resume_kind = resume_stop;
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ public:
|
||||||
|
|
||||||
void post_attach (int) override;
|
void post_attach (int) override;
|
||||||
|
|
||||||
void follow_fork (bool, bool) override;
|
void follow_fork (ptid_t, target_waitkind, bool, bool) override;
|
||||||
|
|
||||||
std::vector<static_tracepoint_marker>
|
std::vector<static_tracepoint_marker>
|
||||||
static_tracepoint_markers_by_strid (const char *id) override;
|
static_tracepoint_markers_by_strid (const char *id) override;
|
||||||
|
|
|
@ -194,17 +194,15 @@ obsd_nat_target::post_startup_inferior (ptid_t pid)
|
||||||
the ptid of the followed inferior. */
|
the ptid of the followed inferior. */
|
||||||
|
|
||||||
void
|
void
|
||||||
obsd_nat_target::follow_fork (bool follow_child, bool detach_fork)
|
obsd_nat_target::follow_fork (ptid_t child_ptid, target_waitkind fork_kind,
|
||||||
|
bool follow_child, bool detach_fork)
|
||||||
{
|
{
|
||||||
if (!follow_child)
|
if (!follow_child)
|
||||||
{
|
{
|
||||||
struct thread_info *tp = inferior_thread ();
|
|
||||||
pid_t child_pid = tp->pending_follow.value.related_pid.pid ();
|
|
||||||
|
|
||||||
/* Breakpoints have already been detached from the child by
|
/* Breakpoints have already been detached from the child by
|
||||||
infrun.c. */
|
infrun.c. */
|
||||||
|
|
||||||
if (ptrace (PT_DETACH, child_pid, (PTRACE_TYPE_ARG3)1, 0) == -1)
|
if (ptrace (PT_DETACH, child_ptid.pid (), (PTRACE_TYPE_ARG3)1, 0) == -1)
|
||||||
perror_with_name (("ptrace"));
|
perror_with_name (("ptrace"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ class obsd_nat_target : public inf_ptrace_target
|
||||||
ptid_t wait (ptid_t, struct target_waitstatus *, target_wait_flags) override;
|
ptid_t wait (ptid_t, struct target_waitstatus *, target_wait_flags) override;
|
||||||
|
|
||||||
#ifdef PT_GET_PROCESS_STATE
|
#ifdef PT_GET_PROCESS_STATE
|
||||||
void follow_fork (bool, bool) override;
|
void follow_fork (ptid_t, target_waitkind, bool, bool) override;
|
||||||
|
|
||||||
int insert_fork_catchpoint (int) override;
|
int insert_fork_catchpoint (int) override;
|
||||||
|
|
||||||
|
|
18
gdb/remote.c
18
gdb/remote.c
|
@ -682,7 +682,7 @@ public:
|
||||||
|
|
||||||
const struct btrace_config *btrace_conf (const struct btrace_target_info *) override;
|
const struct btrace_config *btrace_conf (const struct btrace_target_info *) override;
|
||||||
bool augmented_libraries_svr4_read () override;
|
bool augmented_libraries_svr4_read () override;
|
||||||
void follow_fork (bool, bool) override;
|
void follow_fork (ptid_t, target_waitkind, bool, bool) override;
|
||||||
void follow_exec (inferior *, ptid_t, const char *) override;
|
void follow_exec (inferior *, ptid_t, const char *) override;
|
||||||
int insert_fork_catchpoint (int) override;
|
int insert_fork_catchpoint (int) override;
|
||||||
int remove_fork_catchpoint (int) override;
|
int remove_fork_catchpoint (int) override;
|
||||||
|
@ -5920,13 +5920,13 @@ extended_remote_target::detach (inferior *inf, int from_tty)
|
||||||
remote target as well. */
|
remote target as well. */
|
||||||
|
|
||||||
void
|
void
|
||||||
remote_target::follow_fork (bool follow_child, bool detach_fork)
|
remote_target::follow_fork (ptid_t child_ptid, target_waitkind fork_kind,
|
||||||
|
bool follow_child, bool detach_fork)
|
||||||
{
|
{
|
||||||
struct remote_state *rs = get_remote_state ();
|
struct remote_state *rs = get_remote_state ();
|
||||||
enum target_waitkind kind = inferior_thread ()->pending_follow.kind;
|
|
||||||
|
|
||||||
if ((kind == TARGET_WAITKIND_FORKED && remote_fork_event_p (rs))
|
if ((fork_kind == TARGET_WAITKIND_FORKED && remote_fork_event_p (rs))
|
||||||
|| (kind == TARGET_WAITKIND_VFORKED && remote_vfork_event_p (rs)))
|
|| (fork_kind == TARGET_WAITKIND_VFORKED && remote_vfork_event_p (rs)))
|
||||||
{
|
{
|
||||||
/* When following the parent and detaching the child, we detach
|
/* When following the parent and detaching the child, we detach
|
||||||
the child here. For the case of following the child and
|
the child here. For the case of following the child and
|
||||||
|
@ -5937,13 +5937,7 @@ remote_target::follow_fork (bool follow_child, bool detach_fork)
|
||||||
if (detach_fork && !follow_child)
|
if (detach_fork && !follow_child)
|
||||||
{
|
{
|
||||||
/* Detach the fork child. */
|
/* Detach the fork child. */
|
||||||
ptid_t child_ptid;
|
remote_detach_pid (child_ptid.pid ());
|
||||||
pid_t child_pid;
|
|
||||||
|
|
||||||
child_ptid = inferior_thread ()->pending_follow.value.related_pid;
|
|
||||||
child_pid = child_ptid.pid ();
|
|
||||||
|
|
||||||
remote_detach_pid (child_pid);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,6 +174,8 @@
|
||||||
target_debug_do_print (host_address_to_string (X.data ()))
|
target_debug_do_print (host_address_to_string (X.data ()))
|
||||||
#define target_debug_print_gdb_unique_xmalloc_ptr_char(X) \
|
#define target_debug_print_gdb_unique_xmalloc_ptr_char(X) \
|
||||||
target_debug_do_print (X.get ())
|
target_debug_do_print (X.get ())
|
||||||
|
#define target_debug_print_target_waitkind(X) \
|
||||||
|
target_debug_do_print (pulongest (X))
|
||||||
|
|
||||||
static void
|
static void
|
||||||
target_debug_print_struct_target_waitstatus_p (struct target_waitstatus *status)
|
target_debug_print_struct_target_waitstatus_p (struct target_waitstatus *status)
|
||||||
|
|
|
@ -56,7 +56,7 @@ struct dummy_target : public target_ops
|
||||||
int remove_fork_catchpoint (int arg0) override;
|
int remove_fork_catchpoint (int arg0) override;
|
||||||
int insert_vfork_catchpoint (int arg0) override;
|
int insert_vfork_catchpoint (int arg0) override;
|
||||||
int remove_vfork_catchpoint (int arg0) override;
|
int remove_vfork_catchpoint (int arg0) override;
|
||||||
void follow_fork (bool arg0, bool arg1) override;
|
void follow_fork (ptid_t arg0, target_waitkind arg1, bool arg2, bool arg3) override;
|
||||||
int insert_exec_catchpoint (int arg0) override;
|
int insert_exec_catchpoint (int arg0) override;
|
||||||
int remove_exec_catchpoint (int arg0) override;
|
int remove_exec_catchpoint (int arg0) override;
|
||||||
void follow_exec (inferior *arg0, ptid_t arg1, const char *arg2) override;
|
void follow_exec (inferior *arg0, ptid_t arg1, const char *arg2) override;
|
||||||
|
@ -231,7 +231,7 @@ struct debug_target : public target_ops
|
||||||
int remove_fork_catchpoint (int arg0) override;
|
int remove_fork_catchpoint (int arg0) override;
|
||||||
int insert_vfork_catchpoint (int arg0) override;
|
int insert_vfork_catchpoint (int arg0) override;
|
||||||
int remove_vfork_catchpoint (int arg0) override;
|
int remove_vfork_catchpoint (int arg0) override;
|
||||||
void follow_fork (bool arg0, bool arg1) override;
|
void follow_fork (ptid_t arg0, target_waitkind arg1, bool arg2, bool arg3) override;
|
||||||
int insert_exec_catchpoint (int arg0) override;
|
int insert_exec_catchpoint (int arg0) override;
|
||||||
int remove_exec_catchpoint (int arg0) override;
|
int remove_exec_catchpoint (int arg0) override;
|
||||||
void follow_exec (inferior *arg0, ptid_t arg1, const char *arg2) override;
|
void follow_exec (inferior *arg0, ptid_t arg1, const char *arg2) override;
|
||||||
|
@ -1519,26 +1519,30 @@ debug_target::remove_vfork_catchpoint (int arg0)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
target_ops::follow_fork (bool arg0, bool arg1)
|
target_ops::follow_fork (ptid_t arg0, target_waitkind arg1, bool arg2, bool arg3)
|
||||||
{
|
{
|
||||||
this->beneath ()->follow_fork (arg0, arg1);
|
this->beneath ()->follow_fork (arg0, arg1, arg2, arg3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dummy_target::follow_fork (bool arg0, bool arg1)
|
dummy_target::follow_fork (ptid_t arg0, target_waitkind arg1, bool arg2, bool arg3)
|
||||||
{
|
{
|
||||||
default_follow_fork (this, arg0, arg1);
|
default_follow_fork (this, arg0, arg1, arg2, arg3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
debug_target::follow_fork (bool arg0, bool arg1)
|
debug_target::follow_fork (ptid_t arg0, target_waitkind arg1, bool arg2, bool arg3)
|
||||||
{
|
{
|
||||||
fprintf_unfiltered (gdb_stdlog, "-> %s->follow_fork (...)\n", this->beneath ()->shortname ());
|
fprintf_unfiltered (gdb_stdlog, "-> %s->follow_fork (...)\n", this->beneath ()->shortname ());
|
||||||
this->beneath ()->follow_fork (arg0, arg1);
|
this->beneath ()->follow_fork (arg0, arg1, arg2, arg3);
|
||||||
fprintf_unfiltered (gdb_stdlog, "<- %s->follow_fork (", this->beneath ()->shortname ());
|
fprintf_unfiltered (gdb_stdlog, "<- %s->follow_fork (", this->beneath ()->shortname ());
|
||||||
target_debug_print_bool (arg0);
|
target_debug_print_ptid_t (arg0);
|
||||||
fputs_unfiltered (", ", gdb_stdlog);
|
fputs_unfiltered (", ", gdb_stdlog);
|
||||||
target_debug_print_bool (arg1);
|
target_debug_print_target_waitkind (arg1);
|
||||||
|
fputs_unfiltered (", ", gdb_stdlog);
|
||||||
|
target_debug_print_bool (arg2);
|
||||||
|
fputs_unfiltered (", ", gdb_stdlog);
|
||||||
|
target_debug_print_bool (arg3);
|
||||||
fputs_unfiltered (")\n", gdb_stdlog);
|
fputs_unfiltered (")\n", gdb_stdlog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2701,7 +2701,8 @@ target_program_signals (gdb::array_view<const unsigned char> program_signals)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
default_follow_fork (struct target_ops *self, bool follow_child,
|
default_follow_fork (struct target_ops *self, ptid_t child_ptid,
|
||||||
|
target_waitkind fork_kind, bool follow_child,
|
||||||
bool detach_fork)
|
bool detach_fork)
|
||||||
{
|
{
|
||||||
/* Some target returned a fork event, but did not know how to follow it. */
|
/* Some target returned a fork event, but did not know how to follow it. */
|
||||||
|
@ -2712,11 +2713,12 @@ default_follow_fork (struct target_ops *self, bool follow_child,
|
||||||
/* See target.h. */
|
/* See target.h. */
|
||||||
|
|
||||||
void
|
void
|
||||||
target_follow_fork (bool follow_child, bool detach_fork)
|
target_follow_fork (ptid_t child_ptid, target_waitkind fork_kind,
|
||||||
|
bool follow_child, bool detach_fork)
|
||||||
{
|
{
|
||||||
target_ops *target = current_inferior ()->top_target ();
|
target_ops *target = current_inferior ()->top_target ();
|
||||||
|
|
||||||
return target->follow_fork (follow_child, detach_fork);
|
return target->follow_fork (child_ptid, fork_kind, follow_child, detach_fork);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* See target.h. */
|
/* See target.h. */
|
||||||
|
|
15
gdb/target.h
15
gdb/target.h
|
@ -636,7 +636,7 @@ struct target_ops
|
||||||
TARGET_DEFAULT_RETURN (1);
|
TARGET_DEFAULT_RETURN (1);
|
||||||
virtual int remove_vfork_catchpoint (int)
|
virtual int remove_vfork_catchpoint (int)
|
||||||
TARGET_DEFAULT_RETURN (1);
|
TARGET_DEFAULT_RETURN (1);
|
||||||
virtual void follow_fork (bool, bool)
|
virtual void follow_fork (ptid_t, target_waitkind, bool, bool)
|
||||||
TARGET_DEFAULT_FUNC (default_follow_fork);
|
TARGET_DEFAULT_FUNC (default_follow_fork);
|
||||||
virtual int insert_exec_catchpoint (int)
|
virtual int insert_exec_catchpoint (int)
|
||||||
TARGET_DEFAULT_RETURN (1);
|
TARGET_DEFAULT_RETURN (1);
|
||||||
|
@ -1713,13 +1713,14 @@ extern int target_insert_vfork_catchpoint (int pid);
|
||||||
|
|
||||||
extern int target_remove_vfork_catchpoint (int pid);
|
extern int target_remove_vfork_catchpoint (int pid);
|
||||||
|
|
||||||
/* If the inferior forks or vforks, this function will be called at
|
/* Call the follow_fork method on the current target stack.
|
||||||
the next resume in order to perform any bookkeeping and fiddling
|
|
||||||
necessary to continue debugging either the parent or child, as
|
|
||||||
requested, and releasing the other. Information about the fork
|
|
||||||
or vfork event is available via get_last_target_status (). */
|
|
||||||
|
|
||||||
void target_follow_fork (bool follow_child, bool detach_fork);
|
This function is called when the inferior forks or vforks, to perform any
|
||||||
|
bookkeeping and fiddling necessary to continue debugging either the parent,
|
||||||
|
the child or both. */
|
||||||
|
|
||||||
|
void target_follow_fork (ptid_t child_ptid, target_waitkind fork_kind,
|
||||||
|
bool follow_child, bool detach_fork);
|
||||||
|
|
||||||
/* Handle the target-specific bookkeeping required when the inferior makes an
|
/* Handle the target-specific bookkeeping required when the inferior makes an
|
||||||
exec call.
|
exec call.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue