| 1 | /* Functions and data responsible for forking the inferior process. |
| 2 | |
| 3 | Copyright (C) 1986-2020 Free Software Foundation, Inc. |
| 4 | |
| 5 | This file is part of GDB. |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 3 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 19 | |
| 20 | #ifndef NAT_FORK_INFERIOR_H |
| 21 | #define NAT_FORK_INFERIOR_H |
| 22 | |
| 23 | #include <string> |
| 24 | #include "gdbsupport/function-view.h" |
| 25 | |
| 26 | struct process_stratum_target; |
| 27 | |
| 28 | /* Number of traps that happen between exec'ing the shell to run an |
| 29 | inferior and when we finally get to the inferior code, not counting |
| 30 | the exec for the shell. This is 1 on all supported |
| 31 | implementations. */ |
| 32 | #define START_INFERIOR_TRAPS_EXPECTED 1 |
| 33 | |
| 34 | /* Start an inferior Unix child process and sets inferior_ptid to its |
| 35 | pid. EXEC_FILE is the file to run. ALLARGS is a string containing |
| 36 | the arguments to the program. ENV is the environment vector to |
| 37 | pass. SHELL_FILE is the shell file, or NULL if we should pick |
| 38 | one. EXEC_FUN is the exec(2) function to use, or NULL for the default |
| 39 | one. */ |
| 40 | |
| 41 | /* This function is NOT reentrant. Some of the variables have been |
| 42 | made static to ensure that they survive the vfork call. */ |
| 43 | extern pid_t fork_inferior (const char *exec_file_arg, |
| 44 | const std::string &allargs, |
| 45 | char **env, void (*traceme_fun) (), |
| 46 | gdb::function_view<void (int)> init_trace_fun, |
| 47 | void (*pre_trace_fun) (), |
| 48 | const char *shell_file_arg, |
| 49 | void (*exec_fun) (const char *file, |
| 50 | char * const *argv, |
| 51 | char * const *env)); |
| 52 | |
| 53 | /* Accept NTRAPS traps from the inferior. |
| 54 | |
| 55 | Return the ptid of the inferior being started. */ |
| 56 | extern ptid_t startup_inferior (process_stratum_target *proc_target, |
| 57 | pid_t pid, int ntraps, |
| 58 | struct target_waitstatus *mystatus, |
| 59 | ptid_t *myptid); |
| 60 | |
| 61 | /* Perform any necessary tasks before a fork/vfork takes place. ARGS |
| 62 | is a string containing all the arguments received by the inferior. |
| 63 | This function is mainly used by fork_inferior. */ |
| 64 | extern void prefork_hook (const char *args); |
| 65 | |
| 66 | /* Perform any necessary tasks after a fork/vfork takes place. This |
| 67 | function is mainly used by fork_inferior. */ |
| 68 | extern void postfork_hook (pid_t pid); |
| 69 | |
| 70 | /* Perform any necessary tasks *on the child* after a fork/vfork takes |
| 71 | place. This function is mainly used by fork_inferior. */ |
| 72 | extern void postfork_child_hook (); |
| 73 | |
| 74 | /* Flush both stdout and stderr. This function needs to be |
| 75 | implemented differently on GDB and GDBserver. */ |
| 76 | extern void gdb_flush_out_err (); |
| 77 | |
| 78 | /* Report an error that happened when starting to trace the inferior |
| 79 | (i.e., when the "traceme_fun" callback is called on fork_inferior) |
| 80 | and bail out. This function does not return. */ |
| 81 | extern void trace_start_error (const char *fmt, ...) |
| 82 | ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2); |
| 83 | |
| 84 | /* Like "trace_start_error", but the error message is constructed by |
| 85 | combining STRING with the system error message for errno. This |
| 86 | function does not return. */ |
| 87 | extern void trace_start_error_with_name (const char *string) |
| 88 | ATTRIBUTE_NORETURN; |
| 89 | |
| 90 | #endif /* NAT_FORK_INFERIOR_H */ |