+2021-05-13 Simon Marchi <simon.marchi@efficios.com>
+
+ * target.h (struct target_ops) <follow_exec>: Add ptid_t
+ parameter.
+ (target_follow_exec): Likewise.
+ * target.c (target_follow_exec): Add ptid_t parameter.
+ * infrun.c (follow_exec): Adjust call to target_follow_exec,
+ don't push target nor create thread.
+ * linux-thread-db.c (class thread_db_target) <follow_exec>: New.
+ (thread_db_target::wait): Just return on TARGET_WAITKIND_EXECD.
+ (thread_db_target::follow_exec): New.
+ * remote.c (class remote_target) <follow_exec>: Add ptid_t parameter.
+ (remote_target::follow_exec): Call
+ process_stratum_target::follow_exec.
+ * target-delegates.c: Re-generate.
+
2021-05-13 Simon Marchi <simon.marchi@efficios.com>
* infrun.c (follow_exec): Call target_follow_fork when
static void
follow_exec (ptid_t ptid, const char *exec_file_target)
{
- struct inferior *inf = current_inferior ();
int pid = ptid.pid ();
ptid_t process_ptid;
previous incarnation of this process. */
no_shared_libraries (NULL, 0);
+ struct inferior *inf = current_inferior ();
+
if (follow_exec_mode_string == follow_exec_mode_new)
{
/* The user wants to keep the old inferior and program spaces
inferior's pid. Having two inferiors with the same pid would confuse
find_inferior_p(t)id. Transfer the terminal state and info from the
old to the new inferior. */
- inf = add_inferior_with_spaces ();
- swap_terminal_info (inf, current_inferior ());
- exit_inferior_silent (current_inferior ());
+ inferior *new_inferior = add_inferior_with_spaces ();
- inf->pid = pid;
- target_follow_exec (inf, exec_file_target);
+ swap_terminal_info (new_inferior, inf);
+ exit_inferior_silent (inf);
- inferior *org_inferior = current_inferior ();
- switch_to_inferior_no_thread (inf);
- inf->push_target (org_inferior->process_target ());
- thread_info *thr = add_thread (inf->process_target (), ptid);
- switch_to_thread (thr);
+ new_inferior->pid = pid;
+ target_follow_exec (new_inferior, ptid, exec_file_target);
+
+ /* We continue with the new inferior. */
+ inf = new_inferior;
}
else
{
around (its description is later cleared/refetched on
restart). */
target_clear_description ();
- target_follow_exec (inf, exec_file_target);
+ target_follow_exec (inf, ptid, exec_file_target);
}
+ gdb_assert (current_inferior () == inf);
gdb_assert (current_program_space == inf->pspace);
/* Attempt to open the exec file. SYMFILE_DEFER_BP_RESET is used
ptid_t wait (ptid_t, struct target_waitstatus *, target_wait_flags) override;
void resume (ptid_t, int, enum gdb_signal) override;
void mourn_inferior () override;
+ void follow_exec (inferior *, ptid_t, const char *) override;
void update_thread_list () override;
std::string pid_to_str (ptid_t) override;
CORE_ADDR get_thread_local_address (ptid_t ptid,
case TARGET_WAITKIND_EXITED:
case TARGET_WAITKIND_THREAD_EXITED:
case TARGET_WAITKIND_SIGNALLED:
+ case TARGET_WAITKIND_EXECD:
return ptid;
}
if (info == NULL)
return ptid;
- if (ourstatus->kind == TARGET_WAITKIND_EXECD)
- {
- /* New image, it may or may not end up using thread_db. Assume
- not unless we find otherwise. */
- delete_thread_db_info (beneath, ptid.pid ());
- current_inferior ()->unpush_target (this);
-
- return ptid;
- }
-
/* Fill in the thread's user-level thread id and status. */
thread_from_lwp (find_thread_ptid (beneath, ptid), ptid);
current_inferior ()->unpush_target (this);
}
+void
+thread_db_target::follow_exec (inferior *follow_inf, ptid_t ptid,
+ const char *execd_pathname)
+{
+ process_stratum_target *beneath
+ = as_process_stratum_target (this->beneath ());
+
+ delete_thread_db_info (beneath, ptid.pid ());
+
+ current_inferior ()->unpush_target (this);
+ beneath->follow_exec (follow_inf, ptid, execd_pathname);
+}
+
struct callback_data
{
struct thread_db_info *info;
return inf->pid != 0;
}
+void
+process_stratum_target::follow_exec (inferior *follow_inf, ptid_t ptid,
+ const char *execd_pathname)
+{
+ inferior *orig_inf = current_inferior ();
+
+ if (orig_inf != follow_inf)
+ {
+ /* Execution continues in a new inferior, push the original inferior's
+ process target on the new inferior's target stack. The process target
+ may decide to unpush itself from the original inferior's target stack
+ after that, at its discretion. */
+ follow_inf->push_target (orig_inf->process_target ());
+ thread_info *t = add_thread (follow_inf->process_target (), ptid);
+
+ /* Leave the new inferior / thread as the current inferior / thread. */
+ switch_to_thread (t);
+ }
+}
+
/* See process-stratum-target.h. */
std::set<process_stratum_target *>
bool has_registers () override;
bool has_execution (inferior *inf) override;
+ /* Default implementation of follow_exec.
+
+ If the current inferior and FOLLOW_INF are different (execution continues
+ in a new inferior), push this process target to FOLLOW_INF's target stack
+ and add an initial thread to FOLLOW_INF. */
+ void follow_exec (inferior *follow_inf, ptid_t ptid,
+ const char *execd_pathname) override;
+
/* True if any thread is, or may be executing. We need to track
this separately because until we fully sync the thread list, we
won't know whether the target is fully stopped, even if we see
const struct btrace_config *btrace_conf (const struct btrace_target_info *) override;
bool augmented_libraries_svr4_read () override;
void follow_fork (bool, bool) override;
- void follow_exec (struct inferior *, const char *) override;
+ void follow_exec (inferior *, ptid_t, const char *) override;
int insert_fork_catchpoint (int) override;
int remove_fork_catchpoint (int) override;
int insert_vfork_catchpoint (int) override;
}
/* Target follow-exec function for remote targets. Save EXECD_PATHNAME
- in the program space of the new inferior. On entry and at return the
- current inferior is the exec'ing inferior. INF is the new exec'd
- inferior, which may be the same as the exec'ing inferior unless
- follow-exec-mode is "new". */
+ in the program space of the new inferior. */
void
-remote_target::follow_exec (struct inferior *inf, const char *execd_pathname)
+remote_target::follow_exec (inferior *follow_inf, ptid_t ptid,
+ const char *execd_pathname)
{
+ process_stratum_target::follow_exec (follow_inf, ptid, execd_pathname);
+
/* We know that this is a target file name, so if it has the "target:"
prefix we strip it off before saving it in the program space. */
if (is_target_filename (execd_pathname))
execd_pathname += strlen (TARGET_SYSROOT_PREFIX);
- set_pspace_remote_exec_file (inf->pspace, execd_pathname);
+ set_pspace_remote_exec_file (follow_inf->pspace, execd_pathname);
}
/* Same as remote_detach, but don't send the "D" packet; just disconnect. */
void follow_fork (bool arg0, bool arg1) override;
int insert_exec_catchpoint (int arg0) override;
int remove_exec_catchpoint (int arg0) override;
- void follow_exec (struct inferior *arg0, const char *arg1) override;
+ void follow_exec (inferior *arg0, ptid_t arg1, const char *arg2) override;
int set_syscall_catchpoint (int arg0, bool arg1, int arg2, gdb::array_view<const int> arg3) override;
void mourn_inferior () override;
void pass_signals (gdb::array_view<const unsigned char> arg0) override;
void follow_fork (bool arg0, bool arg1) override;
int insert_exec_catchpoint (int arg0) override;
int remove_exec_catchpoint (int arg0) override;
- void follow_exec (struct inferior *arg0, const char *arg1) override;
+ void follow_exec (inferior *arg0, ptid_t arg1, const char *arg2) override;
int set_syscall_catchpoint (int arg0, bool arg1, int arg2, gdb::array_view<const int> arg3) override;
void mourn_inferior () override;
void pass_signals (gdb::array_view<const unsigned char> arg0) override;
}
void
-target_ops::follow_exec (struct inferior *arg0, const char *arg1)
+target_ops::follow_exec (inferior *arg0, ptid_t arg1, const char *arg2)
{
- this->beneath ()->follow_exec (arg0, arg1);
+ this->beneath ()->follow_exec (arg0, arg1, arg2);
}
void
-dummy_target::follow_exec (struct inferior *arg0, const char *arg1)
+dummy_target::follow_exec (inferior *arg0, ptid_t arg1, const char *arg2)
{
}
void
-debug_target::follow_exec (struct inferior *arg0, const char *arg1)
+debug_target::follow_exec (inferior *arg0, ptid_t arg1, const char *arg2)
{
fprintf_unfiltered (gdb_stdlog, "-> %s->follow_exec (...)\n", this->beneath ()->shortname ());
- this->beneath ()->follow_exec (arg0, arg1);
+ this->beneath ()->follow_exec (arg0, arg1, arg2);
fprintf_unfiltered (gdb_stdlog, "<- %s->follow_exec (", this->beneath ()->shortname ());
- target_debug_print_struct_inferior_p (arg0);
+ target_debug_print_inferior_p (arg0);
fputs_unfiltered (", ", gdb_stdlog);
- target_debug_print_const_char_p (arg1);
+ target_debug_print_ptid_t (arg1);
+ fputs_unfiltered (", ", gdb_stdlog);
+ target_debug_print_const_char_p (arg2);
fputs_unfiltered (")\n", gdb_stdlog);
}
return target->follow_fork (follow_child, detach_fork);
}
-/* Target wrapper for follow exec hook. */
+/* See target.h. */
void
-target_follow_exec (struct inferior *inf, const char *execd_pathname)
+target_follow_exec (inferior *follow_inf, ptid_t ptid,
+ const char *execd_pathname)
{
- current_inferior ()->top_target ()->follow_exec (inf, execd_pathname);
+ current_inferior ()->top_target ()->follow_exec (follow_inf, ptid,
+ execd_pathname);
}
static void
TARGET_DEFAULT_RETURN (1);
virtual int remove_exec_catchpoint (int)
TARGET_DEFAULT_RETURN (1);
- virtual void follow_exec (struct inferior *, const char *)
+ virtual void follow_exec (inferior *, ptid_t, const char *)
TARGET_DEFAULT_IGNORE ();
virtual int set_syscall_catchpoint (int, bool, int,
gdb::array_view<const int>)
void target_follow_fork (bool follow_child, bool detach_fork);
/* Handle the target-specific bookkeeping required when the inferior makes an
- exec call. The current inferior is the inferior that has executed the exec
- call. INF is the inferior in which execution continues post-exec. It is the
- same inferior as the current one if "follow-exec-mode" is "same" but is a new
- one if "follow-exec-mode" is "new". */
+ exec call.
-void target_follow_exec (struct inferior *inf, const char *execd_pathname);
+ The current inferior at the time of the call is the inferior that did the
+ exec. FOLLOW_INF is the inferior in which execution continues post-exec.
+ If "follow-exec-mode" is "same", FOLLOW_INF is the same as the current
+ inferior, meaning that execution continues with the same inferior. If
+ "follow-exec-mode" is "new", FOLLOW_INF is a different inferior, meaning
+ that execution continues in a new inferior.
+
+ On exit, the target must leave FOLLOW_INF as the current inferior. */
+
+void target_follow_exec (inferior *follow_inf, ptid_t ptid,
+ const char *execd_pathname);
/* On some targets, we can catch an inferior exec event when it
occurs. These functions insert/remove an already-created