📄 inflow.c
字号:
/* Low level interface to ptrace, for GDB when running under Unix. Copyright 1986, 1987, 1989, 1991, 1992 Free Software Foundation, Inc.This file is part of GDB.This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#include "defs.h"#include "frame.h"#include "inferior.h"#include "command.h"#include "signals.h"#include "terminal.h"#include "target.h"#ifdef USG#include <sys/types.h>#endif/* Some USG-esque systems (some of which are BSD-esque enough so that USG is not defined) want this header, and it won't do any harm. */#include <fcntl.h>#include <sys/param.h>#include <signal.h>static voidkill_command PARAMS ((char *, int));static voidterminal_ours_1 PARAMS ((int));/* Nonzero if we are debugging an attached outside process rather than an inferior. */int attach_flag;/* Record terminal status separately for debugger and inferior. *//* Does GDB have a terminal (on stdin)? */int gdb_has_a_terminal;#if !defined(__GO32__)static TERMINAL sg_inferior;static TERMINAL sg_ours;#endifstatic int tflags_inferior;static int tflags_ours;#if defined(TIOCGETC) && !defined(TIOCGETC_BROKEN)static struct tchars tc_inferior;static struct tchars tc_ours;#endif#if defined(TIOCGLTC) && !defined(TIOCGLTC_BROKEN)static struct ltchars ltc_inferior;static struct ltchars ltc_ours;#endif#ifdef TIOCLGET/* The line discipline flags. Note that even when gdb_has_a_terminal is true, the ioctl's to get and set the line discipline flags may fail. An example is running gdb under "script" using the streams based interface under SVR4. So we keep track of whether or not the flags we get are valid by setting the *_valid flag, and don't try to reset them unless they are valid. */static int lmode_inferior;static int lmode_inferior_valid;static int lmode_ours;static int lmode_ours_valid;#endif#ifdef TIOCGPGRP# ifdef SHORT_PGRPstatic short pgrp_inferior;static short pgrp_ours;# else /* not def SHORT_PGRP */static int pgrp_inferior;static int pgrp_ours;# endif /* not def SHORT_PGRP */#else /* not def TIOCGPGRP */static void (*sigint_ours) ();static void (*sigquit_ours) ();#endif /* TIOCGPGRP *//* The name of the tty (from the `tty' command) that we gave to the inferior when it was last started. */static char *inferior_thisrun_terminal;/* Nonzero if our terminal settings are in effect. Zero if the inferior's settings are in effect. */static int terminal_is_ours;/* Macro for printing errors from ioctl operations */#define OOPSY(what) \ if (result == -1) \ fprintf(stderr, "[%s failed in terminal_inferior: %s]\n", \ what, strerror (errno))static void terminal_ours_1 ();/* Initialize the terminal settings we record for the inferior, before we actually run the inferior. */voidterminal_init_inferior (){#if !defined(__GO32__) sg_inferior = sg_ours; tflags_inferior = tflags_ours;#if defined(TIOCGETC) && !defined(TIOCGETC_BROKEN) tc_inferior = tc_ours;#endif#if defined(TIOCGLTC) && !defined(TIOCGLTC_BROKEN) ltc_inferior = ltc_ours;#endif#ifdef TIOCLGET lmode_inferior = lmode_ours; lmode_inferior_valid = lmode_ours_valid;#endif#ifdef TIOCGPGRP pgrp_inferior = inferior_pid;#endif /* TIOCGPGRP */#endif terminal_is_ours = 1;}/* Put the inferior's terminal settings into effect. This is preparation for starting or resuming the inferior. */voidterminal_inferior (){#if !defined(__GO32__) int result; if (gdb_has_a_terminal && terminal_is_ours && inferior_thisrun_terminal == 0) { result = fcntl (0, F_SETFL, tflags_inferior); result = fcntl (0, F_SETFL, tflags_inferior); OOPSY ("fcntl F_SETFL"); result = ioctl (0, TIOCSETN, &sg_inferior); OOPSY ("ioctl TIOCSETN");#if defined(TIOCGETC) && !defined(TIOCGETC_BROKEN) result = ioctl (0, TIOCSETC, &tc_inferior); OOPSY ("ioctl TIOCSETC");#endif#if defined(TIOCGLTC) && !defined(TIOCGLTC_BROKEN) result = ioctl (0, TIOCSLTC, <c_inferior); OOPSY ("ioctl TIOCSLTC");#endif#ifdef TIOCLSET if (lmode_inferior_valid) { result = ioctl (0, TIOCLSET, &lmode_inferior); OOPSY ("ioctl TIOCLSET"); }#endif#ifdef TIOCGPGRP result = ioctl (0, TIOCSPGRP, &pgrp_inferior); /* If we attached to the process, we might or might not be sharing a terminal. Avoid printing error msg if we are unable to set our terminal's process group to his process group ID. */ if (!attach_flag) { OOPSY ("ioctl TIOCSPGRP"); }#else sigint_ours = (void (*) ()) signal (SIGINT, SIG_IGN); sigquit_ours = (void (*) ()) signal (SIGQUIT, SIG_IGN);#endif /* TIOCGPGRP */ }#endif terminal_is_ours = 0;}/* Put some of our terminal settings into effect, enough to get proper results from our output, but do not change into or out of RAW mode so that no input is discarded. After doing this, either terminal_ours or terminal_inferior should be called to get back to a normal state of affairs. */voidterminal_ours_for_output (){ terminal_ours_1 (1);}/* Put our terminal settings into effect. First record the inferior's terminal settings so they can be restored properly later. */voidterminal_ours (){ terminal_ours_1 (0);}static voidterminal_ours_1 (output_only) int output_only;{#if !defined(__GO32__) int result;#ifdef TIOCGPGRP /* Ignore this signal since it will happen when we try to set the pgrp. */ void (*osigttou) ();#endif /* TIOCGPGRP */ /* Checking inferior_thisrun_terminal is necessary so that if GDB is running in the background, it won't block trying to do the ioctl()'s below. Checking gdb_has_a_terminal avoids attempting all the ioctl's when running in batch. */ if (inferior_thisrun_terminal != 0 || gdb_has_a_terminal == 0) return; if (!terminal_is_ours) { terminal_is_ours = 1;#ifdef TIOCGPGRP osigttou = (void (*) ()) signal (SIGTTOU, SIG_IGN); result = ioctl (0, TIOCGPGRP, &pgrp_inferior); result = ioctl (0, TIOCSPGRP, &pgrp_ours); signal (SIGTTOU, osigttou);#else signal (SIGINT, sigint_ours); signal (SIGQUIT, sigquit_ours);#endif /* TIOCGPGRP */ tflags_inferior = fcntl (0, F_GETFL, 0); result = ioctl (0, TIOCGETP, &sg_inferior);#if defined(TIOCGETC) && !defined(TIOCGETC_BROKEN) result = ioctl (0, TIOCGETC, &tc_inferior);#endif#if defined(TIOCGLTC) && !defined(TIOCGLTC_BROKEN) result = ioctl (0, TIOCGLTC, <c_inferior);#endif#ifdef TIOCLGET result = ioctl (0, TIOCLGET, &lmode_inferior); lmode_inferior_valid = (result == 0);#endif }#ifdef HAVE_TERMIO sg_ours.c_lflag |= ICANON; if (output_only && !(sg_inferior.c_lflag & ICANON)) sg_ours.c_lflag &= ~ICANON;#else /* not HAVE_TERMIO */ sg_ours.sg_flags &= ~RAW & ~CBREAK; if (output_only) sg_ours.sg_flags |= (RAW | CBREAK) & sg_inferior.sg_flags;#endif /* not HAVE_TERMIO */ result = fcntl (0, F_SETFL, tflags_ours); result = fcntl (0, F_SETFL, tflags_ours); result = ioctl (0, TIOCSETN, &sg_ours);#if defined(TIOCGETC) && !defined(TIOCGETC_BROKEN) result = ioctl (0, TIOCSETC, &tc_ours);#endif#if defined(TIOCGLTC) && !defined(TIOCGLTC_BROKEN) result = ioctl (0, TIOCSLTC, <c_ours);#endif#ifdef TIOCLGET if (lmode_ours_valid) { result = ioctl (0, TIOCLSET, &lmode_ours); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -