summaryrefslogtreecommitdiff
path: root/gdb/linux-thread-db.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2021-05-13 15:28:20 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2021-05-13 15:29:00 -0400
commit294c36eb6ac9eaf761ec300fd400623ed5175203 (patch)
tree607d3345281a55a1c31d6d273c0e20d56493940d /gdb/linux-thread-db.c
parent2af87c859fe450d4a3a841cf19637a91d53c9486 (diff)
downloadbinutils-gdb-294c36eb6ac9eaf761ec300fd400623ed5175203.tar.gz
gdb: on exec, delegate pushing / unpushing target and adding thread to target_ops::follow_exec
On "exec", some targets need to unpush themselves from the inferior, and do some bookkeeping, like forgetting the data associated to the exec'ing inferior. One such example is the thread-db target. It does so in a special case in thread_db_target::wait, just before returning the TARGET_WAITKIND_EXECD event to its caller. We have another such case in the context of rocm-gdb [1], where the "rocm" target is pushed on top of the linux-nat target. When an exec happens, we want to unpush the rocm target from the exec'ing inferior to close some file descriptors that refer to the pre-exec address space and forget about that inferior. We then want to push the target on the inferior in which execution continues, to open the file descriptors for the post-exec address space. I think that a good way to address this cleanly is to do all this in the target_ops::follow_exec implementations. Make the process_stratum_target::follow_exec implementation have the default behavior of pushing itself to the new inferior's target stack (if execution continues in a new inferior) and add the initial thread. remote_target::follow_exec is an example of process target that wants to do a bit more than the default behavior. So it calls process_stratum_target::follow_exec first and does the extra work second. linux-thread-db (a non-process target) implements follow_exec to do some bookeeping (forget about that process' data), before handing down the event down to the process target (which hits process_stratum_target::follow_exec). gdb/ChangeLog: * 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. Change-Id: I3f96d0ba3ea0dde6540b7e1b4d5cdb01635088c8
Diffstat (limited to 'gdb/linux-thread-db.c')
-rw-r--r--gdb/linux-thread-db.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index 1c6ea4debd8..2c75cd60794 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;