This is the mail archive of the libc-hacker@cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

gdb not setting controlling terminal (+patch)


Hello

I'm resending my own report about a bug in gdb-4.17.0.11/Linux,
now for gdb-4.18 and with a partial fix.

The original report is included at the end of this message, and
everything in it remains valid except the version of gdb.
The system is i586-pc-linux-gnu, kernel 2.2.5, glibc 2.1.
gdb-4.18 was ./configure'd with --prefix=/usr --disable-nls.

The problem is with gdb's 'tty' command. The gdb manual reads:

    [...] It also resets the controlling terminal for the child
    process, for future `run' commands.  For example,

         tty /dev/ttyb

    directs that processes started with subsequent `run' commands default
    to do input and output on the terminal `/dev/ttyb' and have that as
    their controlling terminal.

However on this system 'tty' has no effect on the controlling terminal.
The controlling terminal of the child appears the same as that of gdb.
See the original report below for a resulting real-life problem
(a program under gdb tries to read from /dev/tty and fails with SIGTTIN).

In gdb-4.16 (at least on linux-libc5 systems), an effect of 'tty'
was to run a process with no controlling terminal at all.
And this is better for practical purposes.

The code doing this is still there in the source (file inflow.c,
function 'new_tty', a piece of code under '#ifdef TIOCNOTTY').
But it does not work for a silly reason - inflow.c does not manage
to include <sys/ioctl.h>!  So TIOCNOTTY is not defined there and
the code is not compiled in. Including <sys/ioctl.h> returns the
old behavior with no controlling terminal.

Here is the patch.

--- gdb-4.18/gdb/terminal.h.orig	Mon Apr 12 20:36:36 1999
+++ gdb-4.18/gdb/terminal.h	Mon Apr 12 20:56:29 1999
@@ -48,6 +48,7 @@
 
 #if defined(HAVE_TERMIOS)
 #include <termios.h>
+#include <sys/ioctl.h>
 #endif
 
 #if !defined(__GO32__) && !defined(_WIN32) && !defined (HAVE_TERMIOS)


The original report follows.

> Subject: gdb not setting controlling terminal
> To: hjl@lucon.org
> Date: Fri, 9 Apr 1999 21:31:31 +0400 (MSD)
> Organization: Steklov Institute of Mathematics at St.Petersburg
> Reply-To: svivanov@pdmi.ras.ru
> 
> Hello
> 
> With gdb-4.17.0.11 under linux-2.2.5 & glibc-2.1 (all compiled
> by egcs-1.1.X), I have the following gdb session on the console:
> 
> -----------
> ~$ gdb /usr/bin/less
> GNU gdb 4.17.0.11 with Linux support
> Copyright 1998 Free Software Foundation, Inc.
> GDB is free software, covered by the GNU General Public License, and you are
> welcome to change it and/or distribute copies of it under certain
> conditions.
> Type "show copying" to see the conditions.
> There is absolutely no warranty for GDB.  Type "show warranty" for details.
> This GDB was configured as "i586-pc-linux-gnu"...
> (no debugging symbols found)...
> (gdb) set args a.c
> (gdb) tty /dev/tty7
> (gdb) run
> Starting program: /usr/bin/less a.c
> (no debugging symbols found)...(no debugging symbols found)...
> Program received signal SIGTTIN, Stopped (tty input).
> 0x400fa354 in __read ()
> (gdb)
> ------------
> 
> This happens after 'less' displayed its first screen (on /dev/tty7).
> 
> 'ps' shows that that less runs _not_ on /dev/tty7 but on /dev/tty1
> where gdb was started.  Looks like 'tty' command in gdb redirects
> stdin/out/err but not the controlling terminal - contrary to the docs.
> 
> /dev/tty7 is a fresh virtual console owned by the appropriate user.
> It is readable and writeable. The above session runs fine on my
> backup system: linux-2.0.33, libc-5.4.44, gdb-4.16.
> 
> Regards
> Sergei
> 



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]