38 #define SHELL_FILE "/bin/sh"
52 char *cp = scratch, *tmp;
57 while (*cp ==
' ' || *cp ==
'\t' || *cp ==
'\n')
68 tmp = strchr (cp,
' ');
70 tmp = strchr (cp,
'\t');
72 tmp = strchr (cp,
'\n');
94 const int shell_file_len = strlen (shell_file);
100 if (shell_file_len < 3)
103 if (shell_file[shell_file_len - 3] ==
'c'
104 && shell_file[shell_file_len - 2] ==
's'
105 && shell_file[shell_file_len - 1] ==
'h')
123 void (*traceme_fun) (
void),
void (*init_trace_fun) (
int),
124 void (*pre_trace_fun) (
void),
char *shell_file_arg,
125 void (*exec_fun)(
const char *file,
char *
const *argv,
129 static char default_shell_file[] =
SHELL_FILE;
131 static int debug_fork = 0;
134 static int debug_setpgrp = 657473;
135 static char *shell_file;
136 static char *exec_file;
147 exec_file = exec_file_arg;
154 shell_file = shell_file_arg;
158 if (shell_file == NULL)
159 shell_file = getenv (
"SHELL");
160 if (shell_file == NULL)
161 shell_file = default_shell_file;
171 int argc = (strlen (allargs) + 1) / 2 + 2;
173 argv = (
char **) alloca (argc *
sizeof (*argv));
189 len = 5 + 4 * strlen (exec_file) + 1 + strlen (allargs) + 1 + 12;
191 len += strlen (exec_wrapper) + 1;
193 shell_command = (
char *) alloca (len);
194 shell_command[0] =
'\0';
196 strcat (shell_command,
"exec ");
202 strcat (shell_command, exec_wrapper);
203 strcat (shell_command,
" ");
244 strcat (shell_command,
"'");
245 for (p = exec_file; *p !=
'\0'; ++p)
248 strcat (shell_command,
"'\\''");
249 else if (*p ==
'!' && escape_bang)
250 strcat (shell_command,
"\\!");
252 strncat (shell_command, p, 1);
254 strcat (shell_command,
"'");
257 strcat (shell_command, exec_file);
259 strcat (shell_command,
" ");
260 strcat (shell_command, allargs);
266 argv = (
char **) alloca (4 *
sizeof (
char *));
267 argv[0] = shell_file;
269 argv[2] = shell_command;
270 argv[3] = (
char *) 0;
291 if (pre_trace_fun != NULL)
305 if (pre_trace_fun || debug_fork)
327 if (debug_setpgrp == -1)
328 perror (
_(
"setpgrp failed in child"));
361 if (exec_fun != NULL)
362 (*exec_fun) (argv[0],
argv, env);
364 execvp (argv[0], argv);
369 for (i = 1; argv[i] != NULL; i++)
379 environ = save_our_env;
403 (*init_trace_fun) (
pid);
416 int pending_execs = ntraps;
417 int terminal_initted = 0;
444 memset (&ws, 0,
sizeof (ws));
466 error (
_(
"During startup program terminated with signal %s, %s."),
475 error (
_(
"During startup program exited with code %d."),
478 error (
_(
"During startup program exited normally."));
484 resume_signal = GDB_SIGNAL_TRAP;
494 if (resume_signal != GDB_SIGNAL_TRAP)
502 if (!terminal_initted)
516 terminal_initted = 1;
519 if (--pending_execs == 0)
536 xfree (exec_wrapper);
545 _(
"Use of shell to start subprocesses is %s.\n"),
556 Set a wrapper for running programs.\n\
557 The wrapper prepares the system and environment for the new program."),
559 Show the wrapper for running programs."), NULL,
564 _(
"Disable use of an execution wrapper."),
569 Set use of shell to start subprocesses. The default is on."),
_(
"\
570 Show use of shell to start subprocesses."), NULL,
void target_terminal_ours(void)
static void unset_exec_wrapper_command(char *args, int from_tty)
static char * exec_wrapper
void new_tty_prefork(const char *ttyname)
void new_tty_postfork(void)
struct ui_file * gdb_stdout
void switch_to_thread(ptid_t ptid)
static void show_startup_with_shell(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static void breakup_args(char *scratch, char **argv)
struct cmd_list_element * setlist
const char * get_inferior_io_terminal(void)
void initialize_file_ftype(void)
void startup_inferior(int ntraps)
void fprintf_filtered(struct ui_file *stream, const char *format,...)
void target_terminal_inferior(void)
void target_resume(ptid_t ptid, int step, enum gdb_signal signal)
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
struct cmd_list_element * showlist
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc, struct cmd_list_element **list)
ptid_t pid_to_ptid(int pid)
struct cmd_list_element * unsetlist
initialize_file_ftype _initialize_fork_child
union target_waitstatus::@161 value
void target_mourn_inferior(void)
int fork_inferior(char *exec_file_arg, char *allargs, char **env, void(*traceme_fun)(void), void(*init_trace_fun)(int), void(*pre_trace_fun)(void), char *shell_file_arg, void(*exec_fun)(const char *file, char *const *argv, char *const *env))
struct thread_info * add_thread_silent(ptid_t ptid)
const char * gdb_signal_to_name(enum gdb_signal)
ptid_t target_wait(ptid_t ptid, struct target_waitstatus *status, int options)
void close_most_fds(void)
int ptid_get_pid(ptid_t ptid)
void target_terminal_init(void)
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
enum target_waitkind kind
struct ui_file * gdb_stderr
char * safe_strerror(int)
static int escape_bang_in_quoted_argument(const char *shell_file)
void add_setshow_filename_cmd(const char *name, enum command_class theclass, char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
struct inferior * current_inferior(void)
char * get_exec_file(int err)
#define target_supports_multi_process()
const char * gdb_signal_to_string(enum gdb_signal)
void gdb_flush(struct ui_file *file)
pid_t create_tty_session(void)
void set_executing(ptid_t ptid, int executing)
void error(const char *fmt,...)
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t int int rusage_t pid_t pid
void inferior_appeared(struct inferior *inf, int pid)
void add_setshow_boolean_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
void init_thread_list(void)
const ULONGEST const LONGEST len