While working on a later patch that required me to understand how GDB
starts up inferiors, I was confused by the
target_ops::post_startup_inferior method.
The post_startup_inferior target function is only called from
inf_ptrace_target::create_inferior.
Part of the target class hierarchy looks like this:
inf_child_target
|
'-- inf_ptrace_target
|
|-- linux_nat_target
|
|-- fbsd_nat_target
|
|-- nbsd_nat_target
|
|-- obsd_nat_target
|
'-- rs6000_nat_target
Every sub-class of inf_ptrace_target, except rs6000_nat_target,
implements ::post_startup_inferior. The rs6000_nat_target picks up
the implementation of ::post_startup_inferior not from
inf_ptrace_target, but from inf_child_target.
No descendent of inf_child_target, outside the inf_ptrace_target
sub-tree, implements ::post_startup_inferior, which isn't really
surprising, as they would never see the method called (remember, the
method is only called from inf_ptrace_target::create_inferior).
What I find confusing is the role inf_child_target plays in
implementing, what is really a helper function for just one of its
descendents.
In this commit I propose that we formally make ::post_startup_inferior
a helper function of inf_ptrace_target. To do this I will remove the
::post_startup_inferior from the target_ops API, and instead make this
a protected, pure virtual function on inf_ptrace_target.
I'll remove the empty implementation of ::post_startup_inferior from
the inf_child_target class, and add a new empty implementation to the
rs6000_nat_target class.
All the other descendents of inf_ptrace_target already provide an
implementation of this method and so don't need to change beyond
making the method protected within their class declarations.
To me, this makes much more sense now. The helper function, which is
only called from within the inf_ptrace_target class, is now a part of
the inf_ptrace_target class.
The only way in which this change is visible to a user is if the user
turns on 'set debug target 1'. With this debug flag on, prior to this
patch the user would see something like:
-> native->post_startup_inferior (...)
<- native->post_startup_inferior (
2588939)
After this patch these lines are no longer present, as the
post_startup_inferior is no longer a top level target method. For me,
this is an acceptable change.
}
\f
-/* Implement the "post_startup_inferior" target_ops method. */
+/* Implement the virtual inf_ptrace_target::post_startup_inferior method. */
void
aarch64_linux_nat_target::post_startup_inferior (ptid_t ptid)
}
#endif
-/* Implement the "post_startup_inferior" target_ops method. */
+/* Implement the virtual inf_ptrace_target::post_startup_inferior method. */
void
fbsd_nat_target::post_startup_inferior (ptid_t pid)
ptid_t wait (ptid_t, struct target_waitstatus *, target_wait_flags) override;
- void post_startup_inferior (ptid_t) override;
void post_attach (int) override;
#ifdef USE_SIGTRAP_SIGINFO
bool supports_disable_randomization () override;
+protected:
+
+ void post_startup_inferior (ptid_t) override;
+
private:
/* Helper routines for use in fetch_registers and store_registers in
subclasses. These routines fetch and store a single set of
current_inferior ()->unpush_target (this);
}
-void
-inf_child_target::post_startup_inferior (ptid_t ptid)
-{
- /* This target doesn't require a meaningful "post startup inferior"
- operation by a debugger. */
-}
-
bool
inf_child_target::can_run ()
{
void interrupt () override;
void pass_ctrlc () override;
- void post_startup_inferior (ptid_t) override;
-
void follow_exec (inferior *follow_inf, ptid_t ptid,
const char *execd_pathname) override;
/* On some targets, there must be some explicit actions taken after
the inferior has been started up. */
- target_post_startup_inferior (ptid);
+ post_startup_inferior (ptid);
}
/* Clean up a rotting corpse of an inferior after it died. */
protected:
/* Cleanup the inferior after a successful ptrace detach. */
void detach_success (inferior *inf);
+
+ /* Some targets don't allow us to request notification of inferior events
+ such as fork and vfork immediately after the inferior is created.
+ (This is because of how gdb creates inferiors via invoking a shell to
+ do it. In such a scenario, if the shell init file has commands in it,
+ the shell will fork and exec for each of those commands, and we will
+ see each such fork event. Very bad.)
+
+ Such targets will supply an appropriate definition for this
+ function. */
+ virtual void post_startup_inferior (ptid_t ptid) = 0;
};
#ifndef __NetBSD__
linux_init_ptrace_procfs (pid, 1);
}
+/* Implement the virtual inf_ptrace_target::post_startup_inferior method. */
+
void
linux_nat_target::post_startup_inferior (ptid_t ptid)
{
char *pid_to_exec_file (int pid) override;
- void post_startup_inferior (ptid_t) override;
-
void post_attach (int) override;
void follow_fork (inferior *, ptid_t, target_waitkind, bool, bool) override;
/* SIGTRAP-like breakpoint status events recognizer. The default
recognizes SIGTRAP only. */
virtual bool low_status_is_event (int status);
+
+protected:
+
+ void post_startup_inferior (ptid_t) override;
};
/* The final/concrete instance. */
netbsd_nat::for_each_thread (pid, fn);
}
-/* Implement the "post_startup_inferior" target_ops method. */
+/* Implement the virtual inf_ptrace_target::post_startup_inferior method. */
void
nbsd_nat_target::post_startup_inferior (ptid_t ptid)
bool thread_alive (ptid_t ptid) override;
const char *thread_name (struct thread_info *thr) override;
- void post_startup_inferior (ptid_t ptid) override;
void post_attach (int pid) override;
void update_thread_list () override;
std::string pid_to_str (ptid_t ptid) override;
ULONGEST *xfered_len) override;
bool supports_dumpcore () override;
void dumpcore (const char *filename) override;
+
+protected:
+ void post_startup_inferior (ptid_t ptid) override;
};
#endif /* netbsd-nat.h */
obsd_enable_proc_events (pid);
}
+/* Implement the virtual inf_ptrace_target::post_startup_inferior method. */
+
void
obsd_nat_target::post_startup_inferior (ptid_t pid)
{
int remove_fork_catchpoint (int) override;
- void post_startup_inferior (ptid_t) override;
-
void post_attach (int) override;
+
+protected:
+ void post_startup_inferior (ptid_t) override;
};
#endif /* obsd-nat.h */
ptid_t wait (ptid_t, struct target_waitstatus *, target_wait_flags) override;
+protected:
+
+ void post_startup_inferior (ptid_t ptid) override
+ { /* Nothing. */ }
+
private:
enum target_xfer_status
xfer_shared_libraries (enum target_object object,
void terminal_info (const char *arg0, int arg1) override;
void kill () override;
void load (const char *arg0, int arg1) override;
- void post_startup_inferior (ptid_t arg0) override;
int insert_fork_catchpoint (int arg0) override;
int remove_fork_catchpoint (int arg0) override;
int insert_vfork_catchpoint (int arg0) override;
void terminal_info (const char *arg0, int arg1) override;
void kill () override;
void load (const char *arg0, int arg1) override;
- void post_startup_inferior (ptid_t arg0) override;
int insert_fork_catchpoint (int arg0) override;
int remove_fork_catchpoint (int arg0) override;
int insert_vfork_catchpoint (int arg0) override;
fputs_unfiltered (")\n", gdb_stdlog);
}
-void
-target_ops::post_startup_inferior (ptid_t arg0)
-{
- this->beneath ()->post_startup_inferior (arg0);
-}
-
-void
-dummy_target::post_startup_inferior (ptid_t arg0)
-{
-}
-
-void
-debug_target::post_startup_inferior (ptid_t arg0)
-{
- fprintf_unfiltered (gdb_stdlog, "-> %s->post_startup_inferior (...)\n", this->beneath ()->shortname ());
- this->beneath ()->post_startup_inferior (arg0);
- fprintf_unfiltered (gdb_stdlog, "<- %s->post_startup_inferior (", this->beneath ()->shortname ());
- target_debug_print_ptid_t (arg0);
- fputs_unfiltered (")\n", gdb_stdlog);
-}
-
int
target_ops::insert_fork_catchpoint (int arg0)
{
/* See target.h. */
-void
-target_post_startup_inferior (ptid_t ptid)
-{
- return current_inferior ()->top_target ()->post_startup_inferior (ptid);
-}
-
-/* See target.h. */
-
int
target_insert_fork_catchpoint (int pid)
{
virtual bool can_create_inferior ();
virtual void create_inferior (const char *, const std::string &,
char **, int);
- virtual void post_startup_inferior (ptid_t)
- TARGET_DEFAULT_IGNORE ();
virtual int insert_fork_catchpoint (int)
TARGET_DEFAULT_RETURN (1);
virtual int remove_fork_catchpoint (int)
extern void target_load (const char *arg, int from_tty);
-/* Some targets (such as ttrace-based HPUX) don't allow us to request
- notification of inferior events such as fork and vork immediately
- after the inferior is created. (This because of how gdb gets an
- inferior created via invoking a shell to do it. In such a scenario,
- if the shell init file has commands in it, the shell will fork and
- exec for each of those commands, and we will see each such fork
- event. Very bad.)
-
- Such targets will supply an appropriate definition for this function. */
-
-extern void target_post_startup_inferior (ptid_t ptid);
-
/* On some targets, we can catch an inferior fork or vfork event when
it occurs. These functions insert/remove an already-created
catchpoint for such events. They return 0 for success, 1 if the
{
}
+/* Implement the virtual inf_ptrace_target::post_startup_inferior method. */
+
void
x86_linux_nat_target::post_startup_inferior (ptid_t ptid)
{
{
virtual ~x86_linux_nat_target () override = 0;
- /* Override the GNU/Linux inferior startup hook. */
- void post_startup_inferior (ptid_t) override;
-
/* Add the description reader. */
const struct target_desc *read_description () override;
void low_delete_thread (struct arch_lwp_info *lwp) override
{ x86_linux_delete_thread (lwp); }
+
+protected:
+ /* Override the GNU/Linux inferior startup hook. */
+ void post_startup_inferior (ptid_t) override;
};
\f