This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
more bits of per-inferior terminal settings.
- From: Pedro Alves <pedro at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Date: Tue, 19 May 2009 03:47:07 +0100
- Subject: more bits of per-inferior terminal settings.
terminal_info->run_terminal needs to be set somewhere. terminal info
also needs to be copied from fork parent to fork child.
inflow.c is mostly about tty related code nowadays, so the best header
for these things is terminal.h, instead of having related functions
declared in scattered headers. If we move the "kill" command to
infcmd.c, and we had a sane source control system, I'd vote for
renaming inflow.c.
Tested on x86_64-linux, and checked in.
--
Pedro Alves
2009-05-19 Pedro Alves <pedro@codesourcery.com>
* fork-child.c: Don't include frame.h. Include terminal.h.
(fork_inferior): Call new_tty_postfork after forking adn adding
the child to the inferior list.
* inferior.h (new_tty_prefork, gdb_has_a_terminal): Don't declare
here.
* inflow.c (struct terminal_info): Remove const qualifier from
`run_terminal' field.
(inferior_thisrun_terminal): Tweak comment.
(inflow_inferior_exit): Release the `run_terminal' field.
(copy_terminal_info): New function.
(new_tty_postfork): New function.
* terminal.h (new_tty_prefork, new_tty, new_tty_postfork,
(copy_terminal_info, gdb_has_a_terminal, gdb_setpgid): Declare.
* inf-ptrace.c: Include terminal.h.
(inf_ptrace_follow_fork): Copy the parent's terminal info to the
child.
* linux-nat.c: Include terminal.h.
(linux_child_follow_fork): Copy the parent's terminal info to the
child.
* inf-ttrace.c: Include terminal.h.
(inf_ttrace_follow_fork): Copy the parent's terminal info to the
child.
---
gdb/fork-child.c | 4 +++-
gdb/inf-ptrace.c | 14 +++++++++-----
gdb/inf-ttrace.c | 7 ++++++-
gdb/inferior.h | 6 ------
gdb/inflow.c | 35 +++++++++++++++++++++++++++++++----
gdb/linux-nat.c | 3 +++
gdb/terminal.h | 14 ++++++++++++++
7 files changed, 66 insertions(+), 17 deletions(-)
Index: src/gdb/fork-child.c
===================================================================
--- src.orig/gdb/fork-child.c 2009-05-19 03:42:52.000000000 +0100
+++ src/gdb/fork-child.c 2009-05-19 03:43:08.000000000 +0100
@@ -22,8 +22,8 @@
#include "defs.h"
#include "gdb_string.h"
-#include "frame.h" /* required by inferior.h */
#include "inferior.h"
+#include "terminal.h"
#include "target.h"
#include "gdb_wait.h"
#include "gdb_vfork.h"
@@ -400,6 +400,8 @@ fork_inferior (char *exec_file_arg, char
/* Needed for wait_for_inferior stuff below. */
inferior_ptid = pid_to_ptid (pid);
+ new_tty_postfork ();
+
/* We have something that executes now. We'll be running through
the shell at this point, but the pid shouldn't change. Targets
supporting MT should fill this task's ptid with more data as soon
Index: src/gdb/inferior.h
===================================================================
--- src.orig/gdb/inferior.h 2009-05-19 03:42:52.000000000 +0100
+++ src/gdb/inferior.h 2009-05-19 03:43:08.000000000 +0100
@@ -213,12 +213,6 @@ extern void startup_inferior (int);
extern char *construct_inferior_arguments (struct gdbarch *, int, char **);
-/* From inflow.c */
-
-extern void new_tty_prefork (const char *);
-
-extern int gdb_has_a_terminal (void);
-
/* From infrun.c */
extern void start_remote (int from_tty);
Index: src/gdb/inflow.c
===================================================================
--- src.orig/gdb/inflow.c 2009-05-19 03:42:52.000000000 +0100
+++ src/gdb/inflow.c 2009-05-19 03:43:08.000000000 +0100
@@ -67,7 +67,7 @@ struct terminal_info
{
/* The name of the tty (from the `tty' command) that we gave to the
inferior when it was started. */
- const char *run_terminal;
+ char *run_terminal;
/* TTY state. We save it whenever the inferior stops, and restore
it when it resumes. */
@@ -109,9 +109,9 @@ static void (*sigquit_ours) ();
/* The name of the tty (from the `tty' command) that we're giving to
the inferior when starting it up. This is only (and should only
- be) used as a transient global by new_tty_prefork, new_tty and
- create_tty_session, called from fork_inferior, while forking a new
- child. */
+ be) used as a transient global by new_tty_prefork,
+ create_tty_session, new_tty and new_tty_postfork, all called from
+ fork_inferior, while forking a new child. */
static const char *inferior_thisrun_terminal;
/* Nonzero if our terminal settings are in effect. Zero if the
@@ -485,11 +485,20 @@ inflow_inferior_exit (int pid)
{
struct inferior *inf = find_inferior_pid (pid);
+ xfree (inf->terminal_info->run_terminal);
xfree (inf->terminal_info);
inf->terminal_info = NULL;
}
void
+copy_terminal_info (struct inferior *to, struct inferior *from)
+{
+ *to->terminal_info = *from->terminal_info;
+ if (from->terminal_info->run_terminal)
+ to->terminal_info->run_terminal = from->terminal_info->run_terminal;
+}
+
+void
term_info (char *arg, int from_tty)
{
target_terminal_info (arg, from_tty);
@@ -668,6 +677,24 @@ new_tty (void)
close (tty);
#endif /* !go32 && !win32 */
}
+
+/* NEW_TTY_POSTFORK is called after forking a new child process, and
+ adding it to the inferior table, to store the TTYNAME being used by
+ the child, or null if it sharing the terminal with gdb. */
+
+void
+new_tty_postfork (void)
+{
+ /* Save the name for later, for determining whether we and the child
+ are sharing a tty. */
+
+ if (inferior_thisrun_terminal)
+ current_inferior ()->terminal_info->run_terminal
+ = xstrdup (inferior_thisrun_terminal);
+
+ inferior_thisrun_terminal = NULL;
+}
+
/* Kill the inferior process. Make us have no inferior. */
Index: src/gdb/terminal.h
===================================================================
--- src.orig/gdb/terminal.h 2009-05-19 03:42:53.000000000 +0100
+++ src/gdb/terminal.h 2009-05-19 03:43:08.000000000 +0100
@@ -76,8 +76,16 @@
#endif /* sgtty */
#endif
+struct inferior;
+
+extern void new_tty_prefork (const char *);
+
extern void new_tty (void);
+extern void new_tty_postfork (void);
+
+extern void copy_terminal_info (struct inferior *to, struct inferior *from);
+
/* Do we have job control? Can be assumed to always be the same within
a given run of GDB. In inflow.c. */
extern int job_control;
@@ -91,4 +99,10 @@ extern int gdb_setpgid (void);
/* Set up a serial structure describing standard input. In inflow.c. */
extern void initialize_stdin_serial (void);
+extern int gdb_has_a_terminal (void);
+
+/* Set the process group of the caller to its own pid, or do nothing
+ if we lack job control. */
+extern int gdb_setpgid (void);
+
#endif /* !defined (TERMINAL_H) */
Index: src/gdb/inf-ptrace.c
===================================================================
--- src.orig/gdb/inf-ptrace.c 2009-05-19 03:42:52.000000000 +0100
+++ src/gdb/inf-ptrace.c 2009-05-19 03:43:08.000000000 +0100
@@ -23,6 +23,7 @@
#include "command.h"
#include "inferior.h"
#include "inflow.h"
+#include "terminal.h"
#include "gdbcore.h"
#include "regcache.h"
@@ -74,14 +75,20 @@ inf_ptrace_follow_fork (struct target_op
CORE_ADDR step_range_start = last_tp->step_range_start;
CORE_ADDR step_range_end = last_tp->step_range_end;
struct frame_id step_frame_id = last_tp->step_frame_id;
- int attach_flag = find_inferior_pid (pid)->attach_flag;
- struct inferior *inf;
+ struct inferior *parent_inf, *child_inf;
struct thread_info *tp;
/* Otherwise, deleting the parent would get rid of this
breakpoint. */
last_tp->step_resume_breakpoint = NULL;
+ parent_inf = find_inferior_pid (pid);
+
+ /* Add the child. */
+ child_inf = add_inferior (fpid);
+ child_inf->attach_flag = parent_inf->attach_flag;
+ copy_terminal_info (child_inf, parent_inf);
+
/* Before detaching from the parent, remove all breakpoints from
it. */
remove_breakpoints ();
@@ -95,9 +102,6 @@ inf_ptrace_follow_fork (struct target_op
/* Delete the parent. */
detach_inferior (pid);
- /* Add the child. */
- inf = add_inferior (fpid);
- inf->attach_flag = attach_flag;
tp = add_thread_silent (inferior_ptid);
tp->step_resume_breakpoint = step_resume_breakpoint;
Index: src/gdb/linux-nat.c
===================================================================
--- src.orig/gdb/linux-nat.c 2009-05-19 03:42:52.000000000 +0100
+++ src/gdb/linux-nat.c 2009-05-19 03:43:08.000000000 +0100
@@ -53,6 +53,7 @@
#include <sys/types.h>
#include "gdb_dirent.h"
#include "xml-support.h"
+#include "terminal.h"
#ifdef HAVE_PERSONALITY
# include <sys/personality.h>
@@ -626,6 +627,7 @@ linux_child_follow_fork (struct target_o
parent_inf = find_inferior_pid (GET_PID (last_ptid));
child_inf->attach_flag = parent_inf->attach_flag;
+ copy_terminal_info (child_inf, parent_inf);
/* Retain child fork in ptrace (stopped) state. */
fp = find_fork_pid (child_pid);
@@ -723,6 +725,7 @@ linux_child_follow_fork (struct target_o
parent_inf = find_inferior_pid (GET_PID (last_ptid));
child_inf->attach_flag = parent_inf->attach_flag;
+ copy_terminal_info (child_inf, parent_inf);
/* If we're vforking, we may want to hold on to the parent until
the child exits or execs. At exec time we can remove the old
Index: src/gdb/inf-ttrace.c
===================================================================
--- src.orig/gdb/inf-ttrace.c 2009-05-19 03:42:52.000000000 +0100
+++ src/gdb/inf-ttrace.c 2009-05-19 03:43:08.000000000 +0100
@@ -28,6 +28,7 @@
#include "gdbcore.h"
#include "gdbthread.h"
#include "inferior.h"
+#include "terminal.h"
#include "target.h"
#include "gdb_assert.h"
@@ -457,6 +458,9 @@ inf_ttrace_follow_fork (struct target_op
if (follow_child)
{
struct inferior *inf;
+ struct inferior *parent_inf;
+
+ parent_inf = find_inferior_pid (pid);
/* Copy user stepping state to the new inferior thread. */
step_resume_breakpoint = last_tp->step_resume_breakpoint;
@@ -470,7 +474,8 @@ inf_ttrace_follow_fork (struct target_op
inferior_ptid = ptid_build (fpid, flwpid, 0);
inf = add_inferior (fpid);
- inf->attach_flag = find_inferior_pid (pid)->attach_flag;
+ inf->attach_flag = parent_inf->attach_flag;
+ copy_terminal_info (inf, parent_inf);
detach_breakpoints (pid);
target_terminal_ours ();