This is the mail archive of the
gdb@sourceware.cygnus.com
mailing list for the GDB project.
Re: Buffering problems with "gdb < foo"
> 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;