aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/ChangeLog16
-rw-r--r--gdb/infrun.c24
-rw-r--r--gdb/linux-thread-db.c25
-rw-r--r--gdb/process-stratum-target.c20
-rw-r--r--gdb/process-stratum-target.h8
-rw-r--r--gdb/remote.c14
-rw-r--r--gdb/target-delegates.c20
-rw-r--r--gdb/target.c8
-rw-r--r--gdb/target.h19
9 files changed, 107 insertions, 47 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index f0ae77e..ad6f308 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,21 @@
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
follow-exec-mode is same.
* target.h (target_follow_fork): Improve doc.
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 3e386aa..7fc56dc 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -1064,7 +1064,6 @@ show_follow_exec_mode_string (struct ui_file *file, int from_tty,
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;
@@ -1167,6 +1166,8 @@ follow_exec (ptid_t ptid, const char *exec_file_target)
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
@@ -1176,18 +1177,16 @@ follow_exec (ptid_t ptid, const char *exec_file_target)
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
{
@@ -1198,9 +1197,10 @@ follow_exec (ptid_t ptid, const char *exec_file_target)
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
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index 1c6ea4d..2c75cd6 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -95,6 +95,7 @@ public:
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,
@@ -1384,6 +1385,7 @@ thread_db_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
case TARGET_WAITKIND_EXITED:
case TARGET_WAITKIND_THREAD_EXITED:
case TARGET_WAITKIND_SIGNALLED:
+ case TARGET_WAITKIND_EXECD:
return ptid;
}
@@ -1393,16 +1395,6 @@ thread_db_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
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);
@@ -1423,6 +1415,19 @@ thread_db_target::mourn_inferior ()
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;
diff --git a/gdb/process-stratum-target.c b/gdb/process-stratum-target.c
index 7191678..c851090 100644
--- a/gdb/process-stratum-target.c
+++ b/gdb/process-stratum-target.c
@@ -84,6 +84,26 @@ process_stratum_target::has_execution (inferior *inf)
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 *>
diff --git a/gdb/process-stratum-target.h b/gdb/process-stratum-target.h
index 6fddbba..31a9775 100644
--- a/gdb/process-stratum-target.h
+++ b/gdb/process-stratum-target.h
@@ -63,6 +63,14 @@ public:
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
diff --git a/gdb/remote.c b/gdb/remote.c
index 8411b29..4dcc551 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -683,7 +683,7 @@ public:
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;
@@ -5925,20 +5925,20 @@ remote_target::follow_fork (bool follow_child, bool detach_fork)
}
/* 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. */
diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c
index ef8c94c..3e759a2 100644
--- a/gdb/target-delegates.c
+++ b/gdb/target-delegates.c
@@ -59,7 +59,7 @@ struct dummy_target : public target_ops
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;
@@ -234,7 +234,7 @@ struct debug_target : public target_ops
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;
@@ -1595,25 +1595,27 @@ debug_target::remove_exec_catchpoint (int arg0)
}
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);
}
diff --git a/gdb/target.c b/gdb/target.c
index 438788e..6babfc5 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -2718,12 +2718,14 @@ target_follow_fork (bool follow_child, bool detach_fork)
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
diff --git a/gdb/target.h b/gdb/target.h
index b80cf88..d867a58 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -642,7 +642,7 @@ struct target_ops
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>)
@@ -1715,12 +1715,19 @@ extern int target_remove_vfork_catchpoint (int pid);
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