This is the mail archive of the
gdb-patches@sourceware.cygnus.com
mailing list for the GDB project.
Re: Buffering problems with "gdb < foo"
- To: ezannoni at cygnus dot com
- Subject: Re: Buffering problems with "gdb < foo"
- From: Eli Zaretskii <eliz at delorie dot com>
- Date: Wed, 8 Mar 2000 04:48:51 -0500 (EST)
- CC: muller at cerbere dot u-strasbg dot fr, gdb at sourceware dot cygnus dot com, gdb-patches at sourceware dot cygnus dot com
- References: <200003070845.JAA27855@cerbere.u-strasbg.fr><200003070851.DAA14463@indy.delorie.com> <14533.8241.716311.478074@kwikemart.cygnus.com>
- Reply-to: Eli Zaretskii <eliz at is dot elta dot co dot il>
> This input_from_terminal_p() function does:
>
> int
> input_from_terminal_p ()
> {
> return gdb_has_a_terminal () && (instream == stdin) & caution;
> }
>
> In my case the gdb_has_a_terminal() returns 0, so the query is not asked.
>
> All seems to work fine fro solaris. What happens on DJGPP? Is
> gdb_has_a terminal() returning 1, maybe?
Yes, gdb_has_a_terminal returned 1 in the DJGPP case.
This turned to be due to a problem in ser-go32.c: it doesn't support
standard handles (those which are connected to a terminal in an
interactive session), whereas GDB expects it to.
I don't know why does gdb_has_a_terminal go through serial.c to find
out about GDB's own the controlling terminal--won't it be easier (and
more portable) just to use isatty?
Anyway, the patch to make the current code in gdb_has_a_terminal work
is below.
2000-03-07 Eli Zaretskii <eliz@is.elta.co.il>
* ser-go32.c (dos_get_tty_state): Fail if the (fake) handle was
not opened by dos_open, but let the 3 standard handles go through
unharmed.
--- gdb/ser-go32.c~0 Wed Feb 23 17:18:50 2000
+++ gdb/ser-go32.c Tue Mar 7 22:19:34 2000
@@ -488,6 +488,10 @@ dos_open (scb, name)
return -1;
}
+ /* FIXME: this is a Bad Idea (tm)! One should *never* invent file
+ handles, since they might be already used by other files/devices.
+ The Right Way to do this is to create a real handle by dup()'ing
+ some existing one. */
fd = name[3] - '1';
port = &ports[fd];
if (port->refcnt++ > 0)
@@ -650,6 +654,19 @@ dos_get_tty_state (scb)
struct dos_ttystate *port = &ports[scb->fd];
struct dos_ttystate *state;
+ /* Are they asking about a port we opened? */
+ if (port->refcnt <= 0)
+ {
+ /* We've never heard about this port. We should fail this call,
+ unless they are asking about one of the 3 standard handles,
+ in which case we pretend the handle was open by us if it is
+ connected to a terminal device. This is beacuse Unix
+ terminals use the serial interface, so GDB expects the
+ standard handles to go through here. */
+ if (scb->fd >= 3 || !isatty (scb->fd))
+ return NULL;
+ }
+
state = (struct dos_ttystate *) xmalloc (sizeof *state);
*state = *port;
return (serial_ttystate) state;