1 /* Low level interface to ptrace, for GDB when running under Unix.
2 Copyright (C) 1986-2019 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "gdbthread.h"
27 #include "observable.h"
30 #include "gdb_select.h"
37 #include "common/job-control.h"
39 #ifdef HAVE_SYS_IOCTL_H
40 #include <sys/ioctl.h>
47 static void pass_signal (int);
49 static void child_terminal_ours_1 (target_terminal_state);
51 /* Record terminal status separately for debugger and inferior. */
53 static struct serial *stdin_serial;
55 /* Terminal related info we need to keep track of. Each inferior
56 holds an instance of this structure --- we save it whenever the
57 corresponding inferior stops, and restore it to the terminal when
58 the inferior is resumed in the foreground. */
61 terminal_info () = default;
64 /* The name of the tty (from the `tty' command) that we gave to the
65 inferior when it was started. */
66 char *run_terminal = nullptr;
68 /* TTY state. We save it whenever the inferior stops, and restore
69 it when it resumes in the foreground. */
70 serial_ttystate ttystate {};
73 /* The terminal's foreground process group. Saved whenever the
74 inferior stops. This is the pgrp displayed by "info terminal".
75 Note that this may be not the inferior's actual process group,
76 since each inferior that we spawn has its own process group, and
77 only one can be in the foreground at a time. When the inferior
78 resumes, if we can determine the inferior's actual pgrp, then we
79 make that the foreground pgrp instead of what was saved here.
80 While it's a bit arbitrary which inferior's pgrp ends up in the
81 foreground when we resume several inferiors, this at least makes
82 'resume inf1+inf2' + 'stop all' + 'resume inf2' end up with
83 inf2's pgrp in the foreground instead of inf1's (which would be
84 problematic since it would be left stopped: Ctrl-C wouldn't work,
86 pid_t process_group = 0;
89 /* fcntl flags. Saved and restored just like ttystate. */
93 /* Our own tty state, which we restore every time we need to deal with
94 the terminal. This is set once, when GDB first starts, and then
95 whenever we enter/leave TUI mode (gdb_save_tty_state). The
96 settings of flags which readline saves and restores are
98 static struct terminal_info our_terminal_info;
100 /* Snapshot of the initial tty state taken during initialization of
101 GDB, before readline/ncurses have had a chance to change it. This
102 is used as the initial tty state given to each new spawned
103 inferior. Unlike our_terminal_info, this is only ever set
105 static serial_ttystate initial_gdb_ttystate;
107 static struct terminal_info *get_inflow_inferior_data (struct inferior *);
109 /* While the inferior is running, we want SIGINT and SIGQUIT to go to the
110 inferior only. If we have job control, that takes care of it. If not,
111 we save our handlers in these two variables and set SIGINT and SIGQUIT
114 static sighandler_t sigint_ours;
116 static sighandler_t sigquit_ours;
119 /* The name of the tty (from the `tty' command) that we're giving to
120 the inferior when starting it up. This is only (and should only
121 be) used as a transient global by new_tty_prefork,
122 create_tty_session, new_tty and new_tty_postfork, all called from
123 fork_inferior, while forking a new child. */
124 static const char *inferior_thisrun_terminal;
126 /* Track who owns GDB's terminal (is it GDB or some inferior?). While
127 target_terminal::is_ours() etc. tracks the core's intention and is
128 independent of the target backend, this tracks the actual state of
129 GDB's own tty. So for example,
131 (target_terminal::is_inferior () && gdb_tty_state == terminal_is_ours)
133 is true when the (native) inferior is not sharing a terminal with
134 GDB (e.g., because we attached to an inferior that is running on a
135 different terminal). */
136 static target_terminal_state gdb_tty_state = target_terminal_state::is_ours;
138 /* See terminal.h. */
141 set_initial_gdb_ttystate (void)
143 /* Note we can't do any of this in _initialize_inflow because at
144 that point stdin_serial has not been created yet. */
146 initial_gdb_ttystate = serial_get_tty_state (stdin_serial);
148 if (initial_gdb_ttystate != NULL)
150 our_terminal_info.ttystate
151 = serial_copy_tty_state (stdin_serial, initial_gdb_ttystate);
153 our_terminal_info.tflags = fcntl (0, F_GETFL, 0);
155 #ifdef HAVE_TERMIOS_H
156 our_terminal_info.process_group = tcgetpgrp (0);
161 /* Does GDB have a terminal (on stdin)? */
164 gdb_has_a_terminal (void)
166 return initial_gdb_ttystate != NULL;
169 /* Macro for printing errors from ioctl operations */
171 #define OOPSY(what) \
173 fprintf_unfiltered(gdb_stderr, "[%s failed in terminal_inferior: %s]\n", \
174 what, safe_strerror (errno))
176 /* Initialize the terminal settings we record for the inferior,
177 before we actually run the inferior. */
180 child_terminal_init (struct target_ops *self)
182 if (!gdb_has_a_terminal ())
185 inferior *inf = current_inferior ();
186 terminal_info *tinfo = get_inflow_inferior_data (inf);
188 #ifdef HAVE_TERMIOS_H
189 /* A child we spawn should be a process group leader (PGID==PID) at
190 this point, though that may not be true if we're attaching to an
192 tinfo->process_group = inf->pid;
195 xfree (tinfo->ttystate);
196 tinfo->ttystate = serial_copy_tty_state (stdin_serial, initial_gdb_ttystate);
199 /* Save the terminal settings again. This is necessary for the TUI
200 when it switches to TUI or non-TUI mode; curses changes the terminal
201 and gdb must be able to restore it correctly. */
204 gdb_save_tty_state (void)
206 if (gdb_has_a_terminal ())
208 xfree (our_terminal_info.ttystate);
209 our_terminal_info.ttystate = serial_get_tty_state (stdin_serial);
213 /* Try to determine whether TTY is GDB's input terminal. Returns
214 TRIBOOL_UNKNOWN if we can't tell. */
217 is_gdb_terminal (const char *tty)
220 struct stat other_tty;
223 res = stat (tty, &other_tty);
225 return TRIBOOL_UNKNOWN;
227 res = fstat (STDIN_FILENO, &gdb_tty);
229 return TRIBOOL_UNKNOWN;
231 return ((gdb_tty.st_dev == other_tty.st_dev
232 && gdb_tty.st_ino == other_tty.st_ino)
237 /* Helper for sharing_input_terminal. Try to determine whether
238 inferior INF is using the same TTY for input as GDB is. Returns
239 TRIBOOL_UNKNOWN if we can't tell. */
242 sharing_input_terminal_1 (inferior *inf)
244 /* Using host-dependent code here is fine, because the
245 child_terminal_foo functions are meant to be used by child/native
247 #if defined (__linux__) || defined (__sun__)
250 xsnprintf (buf, sizeof (buf), "/proc/%d/fd/0", inf->pid);
251 return is_gdb_terminal (buf);
253 return TRIBOOL_UNKNOWN;
257 /* Return true if the inferior is using the same TTY for input as GDB
258 is. If this is true, then we save/restore terminal flags/state.
260 This is necessary because if inf->attach_flag is set, we don't
261 offhand know whether we are sharing a terminal with the inferior or
262 not. Attaching a process without a terminal is one case where we
263 do not; attaching a process which we ran from the same shell as GDB
264 via `&' is one case where we do.
266 If we can't determine, we assume the TTY is being shared. This
267 works OK if you're only debugging one inferior. However, if you're
268 debugging more than one inferior, and e.g., one is spawned by GDB
269 with "run" (sharing terminal with GDB), and another is attached to
270 (and running on a different terminal, as is most common), then it
271 matters, because we can only restore the terminal settings of one
272 of the inferiors, and in that scenario, we want to restore the
273 settings of the "run"'ed inferior.
275 Note, this is not the same as determining whether GDB and the
276 inferior are in the same session / connected to the same
277 controlling tty. An inferior (fork child) may call setsid,
278 disconnecting itself from the ctty, while still leaving
279 stdin/stdout/stderr associated with the original terminal. If
280 we're debugging that process, we should also save/restore terminal
284 sharing_input_terminal (inferior *inf)
286 terminal_info *tinfo = get_inflow_inferior_data (inf);
288 tribool res = sharing_input_terminal_1 (inf);
290 if (res == TRIBOOL_UNKNOWN)
292 /* As fallback, if we can't determine by stat'ing the inferior's
293 tty directly (because it's not supported on this host) and
294 the child was spawned, check whether run_terminal is our tty.
295 This isn't ideal, since this is checking the child's
296 controlling terminal, not the input terminal (which may have
297 been redirected), but is still better than nothing. A false
298 positive ("set inferior-tty" points to our terminal, but I/O
299 was redirected) is much more likely than a false negative
300 ("set inferior-tty" points to some other terminal, and then
301 output was redirected to our terminal), and with a false
302 positive we just end up trying to save/restore terminal
303 settings when we didn't need to or we actually can't. */
304 if (tinfo->run_terminal != NULL)
305 res = is_gdb_terminal (tinfo->run_terminal);
307 /* If we still can't determine, assume yes. */
308 if (res == TRIBOOL_UNKNOWN)
312 return res == TRIBOOL_TRUE;
315 /* Put the inferior's terminal settings into effect. This is
316 preparation for starting or resuming the inferior. */
319 child_terminal_inferior (struct target_ops *self)
321 /* If we resume more than one inferior in the foreground on GDB's
322 terminal, then the first inferior's terminal settings "win".
323 Note that every child process is put in its own process group, so
324 the first process that ends up resumed ends up determining which
325 process group the kernel forwards Ctrl-C/Ctrl-Z (SIGINT/SIGTTOU)
327 if (gdb_tty_state == target_terminal_state::is_inferior)
330 inferior *inf = current_inferior ();
331 terminal_info *tinfo = get_inflow_inferior_data (inf);
333 if (gdb_has_a_terminal ()
334 && tinfo->ttystate != NULL
335 && sharing_input_terminal (inf))
339 /* Ignore SIGTTOU since it will happen when we try to set the
340 terminal's state (if gdb_tty_state is currently
342 scoped_ignore_sigttou ignore_sigttou;
345 result = fcntl (0, F_SETFL, tinfo->tflags);
346 OOPSY ("fcntl F_SETFL");
349 result = serial_set_tty_state (stdin_serial, tinfo->ttystate);
350 OOPSY ("setting tty state");
354 sigint_ours = signal (SIGINT, SIG_IGN);
356 sigquit_ours = signal (SIGQUIT, SIG_IGN);
362 #ifdef HAVE_TERMIOS_H
363 /* If we can't tell the inferior's actual process group,
364 then restore whatever was the foreground pgrp the last
365 time the inferior was running. See also comments
366 describing terminal_state::process_group. */
368 result = tcsetpgrp (0, getpgid (inf->pid));
370 result = tcsetpgrp (0, tinfo->process_group);
375 /* This fails if either GDB has no controlling terminal,
376 e.g., running under 'setsid(1)', or if the inferior
377 is not attached to GDB's controlling terminal. E.g.,
378 if it called setsid to create a new session or used
379 the TIOCNOTTY ioctl, or simply if we've attached to a
380 process running on another terminal and we couldn't
381 tell whether it was sharing GDB's terminal (and so
385 "[tcsetpgrp failed in child_terminal_inferior: %s]\n",
386 safe_strerror (errno));
392 gdb_tty_state = target_terminal_state::is_inferior;
396 /* Put some of our terminal settings into effect,
397 enough to get proper results from our output,
398 but do not change into or out of RAW mode
399 so that no input is discarded.
401 After doing this, either terminal_ours or terminal_inferior
402 should be called to get back to a normal state of affairs.
404 N.B. The implementation is (currently) no different than
405 child_terminal_ours. See child_terminal_ours_1. */
408 child_terminal_ours_for_output (struct target_ops *self)
410 child_terminal_ours_1 (target_terminal_state::is_ours_for_output);
413 /* Put our terminal settings into effect.
414 First record the inferior's terminal settings
415 so they can be restored properly later.
417 N.B. Targets that want to use this with async support must build that
418 support on top of this (e.g., the caller still needs to add stdin to the
419 event loop). E.g., see linux_nat_terminal_ours. */
422 child_terminal_ours (struct target_ops *self)
424 child_terminal_ours_1 (target_terminal_state::is_ours);
427 /* Save the current terminal settings in the inferior's terminal_info
431 child_terminal_save_inferior (struct target_ops *self)
433 /* Avoid attempting all the ioctl's when running in batch. */
434 if (!gdb_has_a_terminal ())
437 inferior *inf = current_inferior ();
438 terminal_info *tinfo = get_inflow_inferior_data (inf);
440 /* No need to save/restore if the inferior is not sharing GDB's
442 if (!sharing_input_terminal (inf))
445 xfree (tinfo->ttystate);
446 tinfo->ttystate = serial_get_tty_state (stdin_serial);
448 #ifdef HAVE_TERMIOS_H
449 tinfo->process_group = tcgetpgrp (0);
453 tinfo->tflags = fcntl (0, F_GETFL, 0);
457 /* Switch terminal state to DESIRED_STATE, either is_ours, or
458 is_ours_for_output. */
461 child_terminal_ours_1 (target_terminal_state desired_state)
463 gdb_assert (desired_state != target_terminal_state::is_inferior);
465 /* Avoid attempting all the ioctl's when running in batch. */
466 if (!gdb_has_a_terminal ())
469 if (gdb_tty_state != desired_state)
471 int result ATTRIBUTE_UNUSED;
473 /* Ignore SIGTTOU since it will happen when we try to set the
475 scoped_ignore_sigttou ignore_sigttou;
477 /* Set tty state to our_ttystate. */
478 serial_set_tty_state (stdin_serial, our_terminal_info.ttystate);
480 /* If we only want output, then leave the inferior's pgrp in the
481 foreground, so that Ctrl-C/Ctrl-Z reach the inferior
483 if (job_control && desired_state == target_terminal_state::is_ours)
485 #ifdef HAVE_TERMIOS_H
486 result = tcsetpgrp (0, our_terminal_info.process_group);
488 /* This fails on Ultrix with EINVAL if you run the testsuite
489 in the background with nohup, and then log out. GDB never
490 used to check for an error here, so perhaps there are other
491 such situations as well. */
493 fprintf_unfiltered (gdb_stderr,
494 "[tcsetpgrp failed in child_terminal_ours: %s]\n",
495 safe_strerror (errno));
500 if (!job_control && desired_state == target_terminal_state::is_ours)
502 signal (SIGINT, sigint_ours);
504 signal (SIGQUIT, sigquit_ours);
509 result = fcntl (0, F_SETFL, our_terminal_info.tflags);
512 gdb_tty_state = desired_state;
516 /* Interrupt the inferior. Implementation of target_interrupt for
517 child/native targets. */
520 child_interrupt (struct target_ops *self)
522 /* Interrupt the first inferior that has a resumed thread. */
523 thread_info *resumed = NULL;
524 for (thread_info *thr : all_non_exited_threads ())
531 if (thr->suspend.waitstatus_pending_p)
537 /* Note that unlike pressing Ctrl-C on the controlling terminal,
538 here we only interrupt one process, not the whole process
539 group. This is because interrupting a process group (with
540 either Ctrl-C or with kill(3) with negative PID) sends a
541 SIGINT to each process in the process group, and we may not
542 be debugging all processes in the process group. */
544 kill (resumed->inf->pid, SIGINT);
549 /* Pass a Ctrl-C to the inferior as-if a Ctrl-C was pressed while the
550 inferior was in the foreground. Implementation of
551 target_pass_ctrlc for child/native targets. */
554 child_pass_ctrlc (struct target_ops *self)
556 gdb_assert (!target_terminal::is_ours ());
558 #ifdef HAVE_TERMIOS_H
561 pid_t term_pgrp = tcgetpgrp (0);
563 /* If there's any inferior sharing our terminal, pass the SIGINT
564 to the terminal's foreground process group. This acts just
565 like the user typed a ^C on the terminal while the inferior
566 was in the foreground. Note that using a negative process
567 number in kill() is a System V-ism. The proper BSD interface
568 is killpg(). However, all modern BSDs support the System V
571 if (term_pgrp != -1 && term_pgrp != our_terminal_info.process_group)
573 kill (-term_pgrp, SIGINT);
579 /* Otherwise, pass the Ctrl-C to the first inferior that was resumed
580 in the foreground. */
581 for (inferior *inf : all_inferiors ())
583 if (inf->terminal_state != target_terminal_state::is_ours)
585 gdb_assert (inf->pid != 0);
588 kill (inf->pid, SIGINT);
594 /* If no inferior was resumed in the foreground, then how did the
595 !is_ours assert above pass? */
596 gdb_assert_not_reached ("no inferior resumed in the fg found");
599 /* Per-inferior data key. */
600 static const struct inferior_key<terminal_info> inflow_inferior_data;
602 terminal_info::~terminal_info ()
604 xfree (run_terminal);
608 /* Get the current svr4 data. If none is found yet, add it now. This
609 function always returns a valid object. */
611 static struct terminal_info *
612 get_inflow_inferior_data (struct inferior *inf)
614 struct terminal_info *info;
616 info = inflow_inferior_data.get (inf);
618 info = inflow_inferior_data.emplace (inf);
623 /* This is a "inferior_exit" observer. Releases the TERMINAL_INFO member
624 of the inferior structure. This field is private to inflow.c, and
625 its type is opaque to the rest of GDB. PID is the target pid of
626 the inferior that is about to be removed from the inferior
630 inflow_inferior_exit (struct inferior *inf)
632 inf->terminal_state = target_terminal_state::is_ours;
633 inflow_inferior_data.clear (inf);
637 copy_terminal_info (struct inferior *to, struct inferior *from)
639 struct terminal_info *tinfo_to, *tinfo_from;
641 tinfo_to = get_inflow_inferior_data (to);
642 tinfo_from = get_inflow_inferior_data (from);
644 xfree (tinfo_to->run_terminal);
645 xfree (tinfo_to->ttystate);
647 *tinfo_to = *tinfo_from;
649 if (tinfo_from->run_terminal)
650 tinfo_to->run_terminal
651 = xstrdup (tinfo_from->run_terminal);
653 if (tinfo_from->ttystate)
655 = serial_copy_tty_state (stdin_serial, tinfo_from->ttystate);
657 to->terminal_state = from->terminal_state;
660 /* See terminal.h. */
663 swap_terminal_info (inferior *a, inferior *b)
665 terminal_info *info_a = inflow_inferior_data.get (a);
666 terminal_info *info_b = inflow_inferior_data.get (b);
668 inflow_inferior_data.set (a, info_b);
669 inflow_inferior_data.set (b, info_a);
671 std::swap (a->terminal_state, b->terminal_state);
675 info_terminal_command (const char *arg, int from_tty)
677 target_terminal::info (arg, from_tty);
681 child_terminal_info (struct target_ops *self, const char *args, int from_tty)
683 struct inferior *inf;
684 struct terminal_info *tinfo;
686 if (!gdb_has_a_terminal ())
688 printf_filtered (_("This GDB does not control a terminal.\n"));
692 if (inferior_ptid == null_ptid)
695 inf = current_inferior ();
696 tinfo = get_inflow_inferior_data (inf);
698 printf_filtered (_("Inferior's terminal status "
699 "(currently saved by GDB):\n"));
701 /* First the fcntl flags. */
705 flags = tinfo->tflags;
707 printf_filtered ("File descriptor flags = ");
710 #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
712 /* (O_ACCMODE) parens are to avoid Ultrix header file bug. */
713 switch (flags & (O_ACCMODE))
716 printf_filtered ("O_RDONLY");
719 printf_filtered ("O_WRONLY");
722 printf_filtered ("O_RDWR");
725 flags &= ~(O_ACCMODE);
728 if (flags & O_NONBLOCK)
729 printf_filtered (" | O_NONBLOCK");
730 flags &= ~O_NONBLOCK;
733 #if defined (O_NDELAY)
734 /* If O_NDELAY and O_NONBLOCK are defined to the same thing, we will
735 print it as O_NONBLOCK, which is good cause that is what POSIX
736 has, and the flag will already be cleared by the time we get here. */
737 if (flags & O_NDELAY)
738 printf_filtered (" | O_NDELAY");
742 if (flags & O_APPEND)
743 printf_filtered (" | O_APPEND");
746 #if defined (O_BINARY)
747 if (flags & O_BINARY)
748 printf_filtered (" | O_BINARY");
753 printf_filtered (" | 0x%x", flags);
754 printf_filtered ("\n");
757 #ifdef HAVE_TERMIOS_H
758 printf_filtered ("Process group = %d\n", (int) tinfo->process_group);
761 serial_print_tty_state (stdin_serial, tinfo->ttystate, gdb_stdout);
764 /* NEW_TTY_PREFORK is called before forking a new child process,
765 so we can record the state of ttys in the child to be formed.
766 TTYNAME is null if we are to share the terminal with gdb;
767 or points to a string containing the name of the desired tty.
769 NEW_TTY is called in new child processes under Unix, which will
770 become debugger target processes. This actually switches to
771 the terminal specified in the NEW_TTY_PREFORK call. */
774 new_tty_prefork (const char *ttyname)
776 /* Save the name for later, for determining whether we and the child
777 are sharing a tty. */
778 inferior_thisrun_terminal = ttyname;
781 #if !defined(__GO32__) && !defined(_WIN32)
782 /* If RESULT, assumed to be the return value from a system call, is
783 negative, print the error message indicated by errno and exit.
784 MSG should identify the operation that failed. */
786 check_syscall (const char *msg, int result)
790 print_sys_errmsg (msg, errno);
799 if (inferior_thisrun_terminal == 0)
801 #if !defined(__GO32__) && !defined(_WIN32)
805 /* Disconnect the child process from our controlling terminal. On some
806 systems (SVR4 for example), this may cause a SIGTTOU, so temporarily
808 tty = open ("/dev/tty", O_RDWR);
811 scoped_ignore_sigttou ignore_sigttou;
813 ioctl (tty, TIOCNOTTY, 0);
818 /* Now open the specified new terminal. */
819 tty = open (inferior_thisrun_terminal, O_RDWR | O_NOCTTY);
820 check_syscall (inferior_thisrun_terminal, tty);
822 /* Avoid use of dup2; doesn't exist on all systems. */
826 check_syscall ("dup'ing tty into fd 0", dup (tty));
831 check_syscall ("dup'ing tty into fd 1", dup (tty));
836 check_syscall ("dup'ing tty into fd 2", dup (tty));
840 /* Make tty our new controlling terminal. */
841 if (ioctl (tty, TIOCSCTTY, 0) == -1)
842 /* Mention GDB in warning because it will appear in the inferior's
843 terminal instead of GDB's. */
844 warning (_("GDB: Failed to set controlling terminal: %s"),
845 safe_strerror (errno));
850 #endif /* !go32 && !win32 */
853 /* NEW_TTY_POSTFORK is called after forking a new child process, and
854 adding it to the inferior table, to store the TTYNAME being used by
855 the child, or null if it sharing the terminal with gdb. */
858 new_tty_postfork (void)
860 /* Save the name for later, for determining whether we and the child
861 are sharing a tty. */
863 if (inferior_thisrun_terminal)
865 struct inferior *inf = current_inferior ();
866 struct terminal_info *tinfo = get_inflow_inferior_data (inf);
868 tinfo->run_terminal = xstrdup (inferior_thisrun_terminal);
871 inferior_thisrun_terminal = NULL;
875 /* Call set_sigint_trap when you need to pass a signal on to an attached
876 process when handling SIGINT. */
879 pass_signal (int signo)
882 kill (inferior_ptid.pid (), SIGINT);
886 static sighandler_t osig;
890 set_sigint_trap (void)
892 struct inferior *inf = current_inferior ();
893 struct terminal_info *tinfo = get_inflow_inferior_data (inf);
895 if (inf->attach_flag || tinfo->run_terminal)
897 osig = signal (SIGINT, pass_signal);
905 clear_sigint_trap (void)
909 signal (SIGINT, osig);
915 /* Create a new session if the inferior will run in a different tty.
916 A session is UNIX's way of grouping processes that share a controlling
917 terminal, so a new one is needed if the inferior terminal will be
918 different from GDB's.
920 Returns the session id of the new session, 0 if no session was created
921 or -1 if an error occurred. */
923 create_tty_session (void)
928 if (!job_control || inferior_thisrun_terminal == 0)
933 warning (_("Failed to create new terminal session: setsid: %s"),
934 safe_strerror (errno));
939 #endif /* HAVE_SETSID */
942 /* Get all the current tty settings (including whether we have a
943 tty at all!). We can't do this in _initialize_inflow because
944 serial_fdopen() won't work until the serial_ops_list is
945 initialized, but we don't want to do it lazily either, so
946 that we can guarantee stdin_serial is opened if there is
949 initialize_stdin_serial (void)
951 stdin_serial = serial_fdopen (0);
955 _initialize_inflow (void)
957 add_info ("terminal", info_terminal_command,
958 _("Print inferior's saved terminal status."));
960 /* OK, figure out whether we have job control. */
963 gdb::observers::inferior_exit.attach (inflow_inferior_exit);