This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: mi tty commands
On Sun, Jun 12, 2005 at 11:07:32PM -0400, Daniel Jacobowitz wrote:
> On Thu, Jun 02, 2005 at 06:16:44PM -0400, Bob Rossi wrote:
> > Index: src/gdb/fork-child.c
> > ===================================================================
> > RCS file: /cvs/src/src/gdb/fork-child.c,v
> > retrieving revision 1.26
> > diff -w -u -r1.26 fork-child.c
> > --- src/gdb/fork-child.c 12 May 2005 20:21:17 -0000 1.26
> > +++ src/gdb/fork-child.c 2 Jun 2005 22:12:31 -0000
> > @@ -138,6 +138,7 @@
> > char **save_our_env;
> > int shell = 0;
> > static char **argv;
> > + const char *inferior_io_terminal = get_inferior_io_terminal ();
> >
> > /* If no exec file handed to us, get it from the exec-file command
> > -- with a good, common error message if none is specified. */
> > @@ -261,7 +262,7 @@
> >
> > /* Tell the terminal handling subsystem what tty we plan to run on;
> > it will just record the information for later. */
> > - new_tty_prefork (inferior_io_terminal);
> > + new_tty_prefork ((char *)inferior_io_terminal);
> >
> > /* It is generally good practice to flush any possible pending stdio
> > output prior to doing a fork, to avoid the possibility of both
>
> Uggh! That's a nasty cast. It made me go look at the code behind
> this. inferior_thisrun_terminal can now be const; so can the argument
> to new_tty_prefork. Then you can lose the nasty cast. The code could
> be cleaned up further, but that's for another day.
Fixed, and thanks for the great suggestion.
> > +void
> > +set_inferior_io_terminal (char *terminal_name)
>
> This argument can be const too.
Fixed.
> > - c = add_com ("tty", class_run, tty_command,
> > - _("Set terminal for future runs of program being debugged."));
> > + /* add the filename of the terminal connected to inferior I/O */
> > + add_setshow_string_noescape_cmd ("inferior-tty", class_run,
> > + &inferior_io_terminal, _("\
> > +Set terminal for future runs of program being debugged."), _("\
> > +Show terminal for future runs of program being debugged."), _("\
> > +Usage: set inferior-tty /dev/pts/1"), NULL, NULL, &setlist, &showlist);
> > set_cmd_completer (c, filename_completer);
> > + add_com_alias ("tty", "set inferior-tty", class_alias, 0);
>
> This seems nice. I was thinking of replacing "tty" with "set tty"
> instead of "set inferior-tty", but I don't have a strong preference one
> way or the other.
I didn't change this, since there is an alias. However, the more I
think about it, it would be fine with me if this was changed to simply
'tty'. Eventually, I might add a console-tty, which is the reason I was
more specific with inferior-tty, instead of just tty. What do you think?
> > @@ -1010,11 +1011,11 @@
> > if (inferior_io_terminal)
> > {
> > if (!in[0])
> > - in = inferior_io_terminal;
> > + in = (char*)inferior_io_terminal;
> > if (!out[0])
> > - out = inferior_io_terminal;
> > + out = (char*)inferior_io_terminal;
> > if (!err[0])
> > - err = inferior_io_terminal;
> > + err = (char*)inferior_io_terminal;
> > }
> >
> > if (in[0])
>
> Can you change the types of in/out/err instead? Casting away const is
> bad mojo.
OK, Done.
> > @@ -2088,7 +2088,24 @@
> >
> > When you use the @code{tty} command or redirect input in the @code{run}
> > command, only the input @emph{for your program} is affected. The input
> > -for @value{GDBN} still comes from your terminal.
> > +for @value{GDBN} still comes from your terminal. @code{tty} is an alias
> > +for @code{set inferior-tty}.
> > +
> > +@cindex inferior tty
> > +@cindex set inferior controlling terminal
> > +You can use the @code{show inferior-tty} command to tell @value{GDBN} to
> > +display the name of the terminal that will be used for future runs of your
> > +program.
>
> If we're going to make "tty" an alias for "set inferior-tty", should we
> update the documentation to refer to "set inferior-tty" everywhere,
> instead of continuing to suggest that users use "tty"?
>
> > +/* Set the inferior terminal device name. */
>
> Formatting.
Done.
> > +/* Print the inferior terminal device name */
>
> Ditto.
Done.
> > + # Test that the commands,
> > + # -inferior-tty-set
> > + # -inferior-tth-show
>
> Typo.
Done.
I do have one problem with this patch, before it can be approved. There
is no file completion for the tty command with the new patch. I can't
figure out how to add file completion with the
add_setshow_string_noescape_cmd command. Do you or anyone else know how
to do this?
Thanks,
Bob Rossi
Index: gdb/ChangeLog
+ * fork-child.c (fork-inferior): Use accessor function for
+ inferior_io_terminal.
+ * infcmd.c (inferior_io_terminal): Make static.
+ (set_inferior_io_terminal): New function.
+ (get_inferior_io_terminal): Ditto.
+ (tty_command): Use accessor function.
+ (_initialize_infcmd): Add inferior_tty setshow variable.
+ (_initialize_infcmd): Remove tty command.
+ (_initialize_infcmd): Add a tty command that is an alias.
+ * inferior.h (set_inferior_io_terminal): New prototype.
+ (get_inferior_io_terminal): Ditto.
+ (new_tty_prefork): Add const qualifier to parameter.
+ * inflow.c (inferior_thisrun_terminal): Add const qualifier.
+ (new_tty_prefork): Add const qualifier to parameter.
+ * nto-procfs (procfs_create_inferior): Use accessor function.
+ (procfs_create_inferior): Add const qualifier to locals.
+ * win32-nat.c (child_create_inferior): Ditto.
+ * mi/mi-cmd-env.c (mi_cmd_inferior_tty_set): New function.
+ (mi_cmd_inferior_tty_set): Ditto.
+ * mi/mi-cmds.c (mi_cmds): Add inferior-tty-set and inferior-tty-show
+ * mi/mi-cmds.h (mi_cmd_inferior_tty_set): Add prototype.
+ (mi_cmd_inferior_tty_show): Ditto.
Index: gdb/doc/ChangeLog
+ * gdb.texinfo (GDB/MI Miscellaneous Commands): Add -inferior-tty-set
+ and -inferior-tty-show.
+ (Input/Output): Document "set/show inferior-tty" and tty alias.
Index: gdb/testsuite/ChangeLog
+ * gdb.mi/mi-basics.exp (test_setshow_inferior_tty): Test MI tty
+ command.
Index: gdb/fork-child.c
===================================================================
RCS file: /cvs/src/src/gdb/fork-child.c,v
retrieving revision 1.26
diff -w -u -r1.26 fork-child.c
--- gdb/fork-child.c 12 May 2005 20:21:17 -0000 1.26
+++ gdb/fork-child.c 17 Jun 2005 21:01:59 -0000
@@ -138,6 +138,7 @@
char **save_our_env;
int shell = 0;
static char **argv;
+ const char *inferior_io_terminal = get_inferior_io_terminal ();
/* If no exec file handed to us, get it from the exec-file command
-- with a good, common error message if none is specified. */
Index: gdb/infcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/infcmd.c,v
retrieving revision 1.138
diff -w -u -r1.138 infcmd.c
--- gdb/infcmd.c 22 May 2005 14:53:34 -0000 1.138
+++ gdb/infcmd.c 17 Jun 2005 21:02:00 -0000
@@ -136,7 +136,7 @@
/* File name for default use for standard in/out in the inferior. */
-char *inferior_io_terminal;
+static char *inferior_io_terminal;
/* Pid of our debugged inferior, or 0 if no inferior now.
Since various parts of infrun.c test this to see whether there is a program
@@ -203,6 +203,24 @@
/* Accessor routines. */
+void
+set_inferior_io_terminal (const char *terminal_name)
+{
+ if (inferior_io_terminal)
+ xfree (inferior_io_terminal);
+
+ if (!terminal_name)
+ inferior_io_terminal = NULL;
+ else
+ inferior_io_terminal = savestring (terminal_name, strlen (terminal_name));
+}
+
+const char *
+get_inferior_io_terminal (void)
+{
+ return inferior_io_terminal;
+}
+
char *
get_inferior_args (void)
{
@@ -376,7 +394,7 @@
if (file == 0)
error_no_arg (_("terminal name for running target process"));
- inferior_io_terminal = savestring (file, strlen (file));
+ set_inferior_io_terminal (file);
}
/* Kill the inferior if already running. This function is designed
@@ -1988,11 +2006,16 @@
void
_initialize_infcmd (void)
{
- struct cmd_list_element *c;
+ struct cmd_list_element *c = NULL;
- c = add_com ("tty", class_run, tty_command,
- _("Set terminal for future runs of program being debugged."));
- set_cmd_completer (c, filename_completer);
+ /* add the filename of the terminal connected to inferior I/O */
+ add_setshow_string_noescape_cmd ("inferior-tty", class_run,
+ &inferior_io_terminal, _("\
+Set terminal for future runs of program being debugged."), _("\
+Show terminal for future runs of program being debugged."), _("\
+Usage: set inferior-tty /dev/pts/1"), NULL, NULL, &setlist, &showlist);
+// set_cmd_completer (setlist, filename_completer);
+ add_com_alias ("tty", "set inferior-tty", class_alias, 0);
add_setshow_optional_filename_cmd ("args", class_run,
&inferior_args, _("\
Index: gdb/inferior.h
===================================================================
RCS file: /cvs/src/src/gdb/inferior.h,v
retrieving revision 1.71
diff -w -u -r1.71 inferior.h
--- gdb/inferior.h 14 May 2005 06:07:42 -0000 1.71
+++ gdb/inferior.h 17 Jun 2005 21:02:00 -0000
@@ -103,9 +103,10 @@
extern void clear_sigio_trap (void);
-/* File name for default use for standard in/out in the inferior. */
+/* Set/get file name for default use for standard in/out in the inferior. */
-extern char *inferior_io_terminal;
+extern void set_inferior_io_terminal (const char *terminal_name);
+extern const char *get_inferior_io_terminal (void);
/* Collected pid, tid, etc. of the debugged inferior. When there's
no inferior, PIDGET (inferior_ptid) will be 0. */
@@ -264,7 +265,7 @@
/* From inflow.c */
-extern void new_tty_prefork (char *);
+extern void new_tty_prefork (const char *);
extern int gdb_has_a_terminal (void);
Index: gdb/inflow.c
===================================================================
RCS file: /cvs/src/src/gdb/inflow.c,v
retrieving revision 1.29
diff -w -u -r1.29 inflow.c
--- gdb/inflow.c 15 Feb 2005 15:49:11 -0000 1.29
+++ gdb/inflow.c 17 Jun 2005 21:02:00 -0000
@@ -94,7 +94,7 @@
/* 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;
+static const char *inferior_thisrun_terminal;
/* Nonzero if our terminal settings are in effect. Zero if the
inferior's settings are in effect. Ignored if !gdb_has_a_terminal
@@ -509,7 +509,7 @@
the terminal specified in the NEW_TTY_PREFORK call. */
void
-new_tty_prefork (char *ttyname)
+new_tty_prefork (const char *ttyname)
{
/* Save the name for later, for determining whether we and the child
are sharing a tty. */
Index: gdb/nto-procfs.c
===================================================================
RCS file: /cvs/src/src/gdb/nto-procfs.c,v
retrieving revision 1.13
diff -w -u -r1.13 nto-procfs.c
--- gdb/nto-procfs.c 15 Feb 2005 15:49:14 -0000 1.13
+++ gdb/nto-procfs.c 17 Jun 2005 21:02:00 -0000
@@ -981,9 +981,10 @@
pid_t pid;
int flags, errn;
char **argv, *args;
- char *in = "", *out = "", *err = "";
+ const char *in = "", *out = "", *err = "";
int fd, fds[3];
sigset_t set;
+ const char *inferior_io_terminal = get_inferior_io_terminal ();
argv = xmalloc (((strlen (allargs) + 1) / (unsigned) 2 + 2) *
sizeof (*argv));
Index: gdb/win32-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/win32-nat.c,v
retrieving revision 1.111
diff -w -u -r1.111 win32-nat.c
--- gdb/win32-nat.c 23 May 2005 19:32:27 -0000 1.111
+++ gdb/win32-nat.c 17 Jun 2005 21:02:01 -0000
@@ -1735,6 +1735,7 @@
const char *sh;
int tty;
int ostdin, ostdout, ostderr;
+ const char *inferior_io_terminal = get_inferior_io_terminal ();
if (!exec_file)
error (_("No executable specified, use `target exec'."));
Index: gdb/doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.261
diff -w -u -r1.261 gdb.texinfo
--- gdb/doc/gdb.texinfo 7 Jun 2005 15:32:38 -0000 1.261
+++ gdb/doc/gdb.texinfo 17 Jun 2005 21:02:06 -0000
@@ -2095,7 +2095,24 @@
When you use the @code{tty} command or redirect input in the @code{run}
command, only the input @emph{for your program} is affected. The input
-for @value{GDBN} still comes from your terminal.
+for @value{GDBN} still comes from your terminal. @code{tty} is an alias
+for @code{set inferior-tty}.
+
+@cindex inferior tty
+@cindex set inferior controlling terminal
+You can use the @code{show inferior-tty} command to tell @value{GDBN} to
+display the name of the terminal that will be used for future runs of your
+program.
+
+@table @code
+@item set inferior-tty /dev/ttyb
+@kindex set inferior-tty
+Set the tty for the program being debugged to /dev/ttyb.
+
+@item show inferior-tty
+@kindex show inferior-tty
+Show the current tty for the program being debugged.
+@end table
@node Attach
@section Debugging an already-running process
@@ -19134,6 +19151,57 @@
(@value{GDBP})
@end smallexample
+@subheading The @code{-inferior-tty-set} Command
+@findex -inferior-tty-set
+
+@subheading Synopsis
+
+@smallexample
+-inferior-tty-set /dev/pts/1
+@end smallexample
+
+Set terminal for future runs of the program being debugged.
+
+@subheading @value{GDBN} Command
+
+The corresponding @value{GDBN} command is @samp{set inferior-tty /dev/pts/1}.
+
+@subheading Example
+
+@smallexample
+(@value{GDBP})
+-inferior-tty-set /dev/pts/1
+^done
+(@value{GDBP})
+@end smallexample
+
+@subheading The @code{-inferior-tty-show} Command
+@findex -inferior-tty-show
+
+@subheading Synopsis
+
+@smallexample
+-inferior-tty-show
+@end smallexample
+
+Show terminal for future runs of program being debugged.
+
+@subheading @value{GDBN} Command
+
+The corresponding @value{GDBN} command is @samp{show inferior-tty /dev/pts/1}.
+
+@subheading Example
+
+@smallexample
+(@value{GDBP})
+-inferior-tty-set /dev/pts/1
+^done
+(@value{GDBP})
+-inferior-tty-show
+^done,inferior_tty_terminal="/dev/pts/1"
+(@value{GDBP})
+@end smallexample
+
@ignore
@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@node GDB/MI Kod Commands
Index: gdb/mi/mi-cmd-env.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmd-env.c,v
retrieving revision 1.8
diff -w -u -r1.8 mi-cmd-env.c
--- gdb/mi/mi-cmd-env.c 11 Feb 2005 04:06:11 -0000 1.8
+++ gdb/mi/mi-cmd-env.c 17 Jun 2005 21:02:06 -0000
@@ -244,6 +244,30 @@
return MI_CMD_DONE;
}
+/* Set the inferior terminal device name. */
+enum mi_cmd_result
+mi_cmd_inferior_tty_set (char *command, char **argv, int argc)
+{
+ set_inferior_io_terminal (argv[0]);
+
+ return MI_CMD_DONE;
+}
+
+/* Print the inferior terminal device name */
+enum mi_cmd_result
+mi_cmd_inferior_tty_show (char *command, char **argv, int argc)
+{
+ const char *inferior_io_terminal = get_inferior_io_terminal ();
+
+ if ( !mi_valid_noargs ("mi_cmd_inferior_tty_show", argc, argv))
+ error (_("mi_cmd_inferior_tty_show: Usage: No args"));
+
+ if (inferior_io_terminal)
+ ui_out_field_string (uiout, "inferior_tty_terminal", inferior_io_terminal);
+
+ return MI_CMD_DONE;
+}
+
void
_initialize_mi_cmd_env (void)
{
Index: gdb/mi/mi-cmds.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmds.c,v
retrieving revision 1.16
diff -w -u -r1.16 mi-cmds.c
--- gdb/mi/mi-cmds.c 11 Feb 2005 18:13:55 -0000 1.16
+++ gdb/mi/mi-cmds.c 17 Jun 2005 21:02:06 -0000
@@ -153,6 +153,8 @@
{ "trace-save", { NULL, 0 }, NULL, NULL },
{ "trace-start", { NULL, 0 }, NULL, NULL },
{ "trace-stop", { NULL, 0 }, NULL, NULL },
+ { "inferior-tty-set", { NULL, 0 }, NULL, mi_cmd_inferior_tty_set},
+ { "inferior-tty-show", { NULL, 0 }, NULL, mi_cmd_inferior_tty_show},
{ "var-assign", { NULL, 0 }, 0, mi_cmd_var_assign},
{ "var-create", { NULL, 0 }, 0, mi_cmd_var_create},
{ "var-delete", { NULL, 0 }, 0, mi_cmd_var_delete},
Index: gdb/mi/mi-cmds.h
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmds.h,v
retrieving revision 1.15
diff -w -u -r1.15 mi-cmds.h
--- gdb/mi/mi-cmds.h 13 Jan 2005 22:08:27 -0000 1.15
+++ gdb/mi/mi-cmds.h 17 Jun 2005 21:02:06 -0000
@@ -96,6 +96,8 @@
extern mi_cmd_args_ftype mi_cmd_target_select;
extern mi_cmd_argv_ftype mi_cmd_thread_list_ids;
extern mi_cmd_argv_ftype mi_cmd_thread_select;
+extern mi_cmd_argv_ftype mi_cmd_inferior_tty_set;
+extern mi_cmd_argv_ftype mi_cmd_inferior_tty_show;
extern mi_cmd_argv_ftype mi_cmd_var_assign;
extern mi_cmd_argv_ftype mi_cmd_var_create;
extern mi_cmd_argv_ftype mi_cmd_var_delete;
Index: gdb/testsuite/gdb.mi/mi-basics.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.mi/mi-basics.exp,v
retrieving revision 1.9
diff -w -u -r1.9 mi-basics.exp
--- gdb/testsuite/gdb.mi/mi-basics.exp 9 Aug 2004 16:32:44 -0000 1.9
+++ gdb/testsuite/gdb.mi/mi-basics.exp 17 Jun 2005 21:02:09 -0000
@@ -236,12 +236,42 @@
}
+proc test_setshow_inferior_tty {} {
+ global mi_gdb_prompt
+
+ # Test that the commands,
+ # -inferior-tty-set
+ # -inferior-tty-show
+ # are setting/getting the same data in GDB.
+
+ mi_gdb_test "301-inferior-tty-show" \
+ "301\\\^done" \
+ "initial tty is empty"
+
+ mi_gdb_test "302-inferior-tty-set /dev/pts/1" \
+ "302\\\^done" \
+ "set tty to /dev/pts/1"
+
+ mi_gdb_test "303-inferior-tty-show" \
+ "303\\\^done,inferior_tty_terminal=\"/dev/pts/1\"" \
+ "tty was set correctly"
+
+ mi_gdb_test "304-inferior-tty-set" \
+ "304\\\^done" \
+ "set tty to the empty string"
+
+ mi_gdb_test "305-inferior-tty-show" \
+ "305\\\^done" \
+ "final tty is empty"
+}
+
if [test_mi_interpreter_selection] {
test_exec_and_symbol_mi_operatons
test_breakpoints_deletion
test_dir_specification
test_cwd_specification
test_path_specification
+ test_setshow_inferior_tty
}
mi_gdb_exit