Exemplo n.º 1
0
void
child_terminal_init_with_pgrp (int pgrp)
{
  struct inferior *inf = current_inferior ();
  struct terminal_info *tinfo = get_inflow_inferior_data (inf);

#ifdef PROCESS_GROUP_TYPE
  /* Store the process group even without a terminal as it is used not
     only to reset the tty foreground process group, but also to
     interrupt the inferior.  */
  tinfo->process_group = pgrp;
#endif

  if (gdb_has_a_terminal ())
    {
      xfree (tinfo->ttystate);
      tinfo->ttystate = serial_copy_tty_state (stdin_serial,
					       our_terminal_info.ttystate);

      /* Make sure that next time we call terminal_inferior (which will be
         before the program runs, as it needs to be), we install the new
         process group.  */
      terminal_is_ours = 1;
    }
}
Exemplo n.º 2
0
Arquivo: inflow.c Projeto: 5kg/gdb
void
terminal_init_inferior_with_pgrp (int pgrp)
{
  if (gdb_has_a_terminal ())
    {
      struct inferior *inf = current_inferior ();
      struct terminal_info *tinfo = get_inflow_inferior_data (inf);

      xfree (tinfo->ttystate);
      tinfo->ttystate = serial_copy_tty_state (stdin_serial,
					       our_terminal_info.ttystate);

#ifdef PROCESS_GROUP_TYPE
      tinfo->process_group = pgrp;
#endif

      /* Make sure that next time we call terminal_inferior (which will be
         before the program runs, as it needs to be), we install the new
         process group.  */
      terminal_is_ours = 1;
    }
}
Exemplo n.º 3
0
PROCESS_GROUP_TYPE
inferior_process_group (void)
{
  return get_inflow_inferior_data (current_inferior ())->process_group;
}
Exemplo n.º 4
0
static void
terminal_ours_1 (int output_only)
{
  struct inferior *inf;
  struct terminal_info *tinfo;

  if (terminal_is_ours)
    return;

  terminal_is_ours = 1;

  /* Checking inferior->run_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.  */

  inf = current_inferior ();
  tinfo = get_inflow_inferior_data (inf);

  if (tinfo->run_terminal != NULL || gdb_has_a_terminal () == 0)
    return;

    {
#ifdef SIGTTOU
      /* Ignore this signal since it will happen when we try to set the
         pgrp.  */
      void (*osigttou) () = NULL;
#endif
      int result;

#ifdef SIGTTOU
      if (job_control)
	osigttou = (void (*)()) signal (SIGTTOU, SIG_IGN);
#endif

      xfree (tinfo->ttystate);
      tinfo->ttystate = serial_get_tty_state (stdin_serial);

#ifdef PROCESS_GROUP_TYPE
      if (!inf->attach_flag)
	/* If setpgrp failed in terminal_inferior, this would give us
	   our process group instead of the inferior's.  See
	   terminal_inferior for details.  */
	tinfo->process_group = gdb_getpgrp ();
#endif

      /* Here we used to set ICANON in our ttystate, but I believe this
         was an artifact from before when we used readline.  Readline sets
         the tty state when it needs to.
         FIXME-maybe: However, query() expects non-raw mode and doesn't
         use readline.  Maybe query should use readline (on the other hand,
         this only matters for HAVE_SGTTY, not termio or termios, I think).  */

      /* Set tty state to our_ttystate.  We don't change in our out of raw
         mode, to avoid flushing input.  We need to do the same thing
         regardless of output_only, because we don't have separate
         terminal_is_ours and terminal_is_ours_for_output flags.  It's OK,
         though, since readline will deal with raw mode when/if it needs to.
       */

      serial_noflush_set_tty_state (stdin_serial, our_terminal_info.ttystate,
				    tinfo->ttystate);

      if (job_control)
	{
#ifdef HAVE_TERMIOS
	  result = tcsetpgrp (0, our_terminal_info.process_group);
#if 0
	  /* This fails on Ultrix with EINVAL if you run the testsuite
	     in the background with nohup, and then log out.  GDB never
	     used to check for an error here, so perhaps there are other
	     such situations as well.  */
	  if (result == -1)
	    fprintf_unfiltered (gdb_stderr, "[tcsetpgrp failed in terminal_ours: %s]\n",
				safe_strerror (errno));
#endif
#endif /* termios */

#ifdef HAVE_SGTTY
	  result = ioctl (0, TIOCSPGRP, &our_terminal_info.process_group);
#endif
	}

#ifdef SIGTTOU
      if (job_control)
	signal (SIGTTOU, osigttou);
#endif

      if (!job_control)
	{
	  signal (SIGINT, sigint_ours);
#ifdef SIGQUIT
	  signal (SIGQUIT, sigquit_ours);
#endif
	}

#ifdef F_GETFL
      tinfo->tflags = fcntl (0, F_GETFL, 0);

      /* Is there a reason this is being done twice?  It happens both
         places we use F_SETFL, so I'm inclined to think perhaps there
         is some reason, however perverse.  Perhaps not though...  */
      result = fcntl (0, F_SETFL, our_terminal_info.tflags);
      result = fcntl (0, F_SETFL, our_terminal_info.tflags);
#endif
    }
}
Exemplo n.º 5
0
void
terminal_inferior (void)
{
  struct inferior *inf;
  struct terminal_info *tinfo;

  if (!terminal_is_ours)
    return;

  inf = current_inferior ();
  tinfo = get_inflow_inferior_data (inf);

  if (gdb_has_a_terminal ()
      && tinfo->ttystate != NULL
      && tinfo->run_terminal == NULL)
    {
      int result;

#ifdef F_GETFL
      /* Is there a reason this is being done twice?  It happens both
         places we use F_SETFL, so I'm inclined to think perhaps there
         is some reason, however perverse.  Perhaps not though...  */
      result = fcntl (0, F_SETFL, tinfo->tflags);
      result = fcntl (0, F_SETFL, tinfo->tflags);
      OOPSY ("fcntl F_SETFL");
#endif

      /* Because we were careful to not change in or out of raw mode in
         terminal_ours, we will not change in our out of raw mode with
         this call, so we don't flush any input.  */
      result = serial_set_tty_state (stdin_serial,
				     tinfo->ttystate);
      OOPSY ("setting tty state");

      if (!job_control)
	{
	  sigint_ours = (void (*)()) signal (SIGINT, SIG_IGN);
#ifdef SIGQUIT
	  sigquit_ours = (void (*)()) signal (SIGQUIT, SIG_IGN);
#endif
	}

      /* If attach_flag is set, we don't know whether we are sharing a
         terminal with the inferior or not.  (attaching a process
         without a terminal is one case where we do not; attaching a
         process which we ran from the same shell as GDB via `&' is
         one case where we do, I think (but perhaps this is not
         `sharing' in the sense that we need to save and restore tty
         state)).  I don't know if there is any way to tell whether we
         are sharing a terminal.  So what we do is to go through all
         the saving and restoring of the tty state, but ignore errors
         setting the process group, which will happen if we are not
         sharing a terminal).  */

      if (job_control)
	{
#ifdef HAVE_TERMIOS
	  result = tcsetpgrp (0, tinfo->process_group);
	  if (!inf->attach_flag)
	    OOPSY ("tcsetpgrp");
#endif

#ifdef HAVE_SGTTY
	  result = ioctl (0, TIOCSPGRP, &tinfo->process_group);
	  if (!inf->attach_flag)
	    OOPSY ("TIOCSPGRP");
#endif
	}

    }
  terminal_is_ours = 0;
}