diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2023-04-03 14:52:02 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@efficios.com> | 2023-04-17 13:47:13 -0400 |
commit | 4a1283c8d56a43a5146744cec6960556d9b40605 (patch) | |
tree | 53d93294ddcff0748b4abed362d1987d21fa5be4 /gdb/infrun.c | |
parent | e49831ba4340688d7685a52099db09d12177945b (diff) | |
download | fsf-binutils-gdb-4a1283c8d56a43a5146744cec6960556d9b40605.zip fsf-binutils-gdb-4a1283c8d56a43a5146744cec6960556d9b40605.tar.gz fsf-binutils-gdb-4a1283c8d56a43a5146744cec6960556d9b40605.tar.bz2 |
gdb: pass execing and following inferior to inferior_execd observers
The upcoming patch to support exec in the amd-dbgapi target needs to
detach amd-dbgapi from the inferior doing the exec and attach amd-dbgapi
to the inferior continuing the execution. They may or may not be the
same, depending on the `set follow-exec-mode` setting. But even if they
are the same, we need to do the detach / attach dance.
With the current observable signature, the observers only receive the
inferior in which execution continues (the "following" inferior).
Change the signature to pass both inferiors, and update all existing
observers.
Change-Id: I259d1ea09f70f43be739378d6023796f2fce2659
Reviewed-By: Pedro Alves <pedro@palves.net>
Diffstat (limited to 'gdb/infrun.c')
-rw-r--r-- | gdb/infrun.c | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/gdb/infrun.c b/gdb/infrun.c index ba56fe3..e77ad31 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -1293,7 +1293,8 @@ follow_exec (ptid_t ptid, const char *exec_file_target) previous incarnation of this process. */ no_shared_libraries (nullptr, 0); - struct inferior *inf = current_inferior (); + inferior *execing_inferior = current_inferior (); + inferior *following_inferior; if (follow_exec_mode_string == follow_exec_mode_new) { @@ -1304,19 +1305,19 @@ 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. */ - inferior *new_inferior = add_inferior_with_spaces (); - - swap_terminal_info (new_inferior, inf); - exit_inferior_silent (inf); + following_inferior = add_inferior_with_spaces (); - new_inferior->pid = pid; - target_follow_exec (new_inferior, ptid, exec_file_target); + swap_terminal_info (following_inferior, execing_inferior); + exit_inferior_silent (execing_inferior); - /* We continue with the new inferior. */ - inf = new_inferior; + following_inferior->pid = pid; } else { + /* follow-exec-mode is "same", we continue execution in the execing + inferior. */ + following_inferior = execing_inferior; + /* The old description may no longer be fit for the new image. E.g, a 64-bit process exec'ed a 32-bit process. Clear the old description; we'll read a new one below. No need to do @@ -1324,18 +1325,20 @@ 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, ptid, exec_file_target); } - gdb_assert (current_inferior () == inf); - gdb_assert (current_program_space == inf->pspace); + target_follow_exec (following_inferior, ptid, exec_file_target); + + gdb_assert (current_inferior () == following_inferior); + gdb_assert (current_program_space == following_inferior->pspace); /* Attempt to open the exec file. SYMFILE_DEFER_BP_RESET is used because the proper displacement for a PIE (Position Independent Executable) main symbol file will only be computed by solib_create_inferior_hook below. breakpoint_re_set would fail to insert the breakpoints with the zero displacement. */ - try_open_exec_file (exec_file_host.get (), inf, SYMFILE_DEFER_BP_RESET); + try_open_exec_file (exec_file_host.get (), following_inferior, + SYMFILE_DEFER_BP_RESET); /* If the target can specify a description, read it. Must do this after flipping to the new executable (because the target supplied @@ -1345,7 +1348,7 @@ follow_exec (ptid_t ptid, const char *exec_file_target) registers. */ target_find_description (); - gdb::observers::inferior_execd.notify (inf); + gdb::observers::inferior_execd.notify (execing_inferior, following_inferior); breakpoint_re_set (); @@ -1622,15 +1625,15 @@ infrun_inferior_exit (struct inferior *inf) } static void -infrun_inferior_execd (inferior *inf) +infrun_inferior_execd (inferior *exec_inf, inferior *follow_inf) { /* If some threads where was doing a displaced step in this inferior at the moment of the exec, they no longer exist. Even if the exec'ing thread doing a displaced step, we don't want to to any fixup nor restore displaced stepping buffer bytes. */ - inf->displaced_step_state.reset (); + follow_inf->displaced_step_state.reset (); - for (thread_info *thread : inf->threads ()) + for (thread_info *thread : follow_inf->threads ()) thread->displaced_step_state.reset (); /* Since an in-line step is done with everything else stopped, if there was @@ -1638,7 +1641,7 @@ infrun_inferior_execd (inferior *inf) thread. */ clear_step_over_info (); - inf->thread_waiting_for_vfork_done = nullptr; + follow_inf->thread_waiting_for_vfork_done = nullptr; } /* If ON, and the architecture supports it, GDB will use displaced |