PATCH: propagate gdb host keyboard interrupts through gdbserver

J.T. Conklin
2001-07-11T10:40:00Z

I just committed the enclosed patch. It's a patch Greg McGary
submitted all too long ago.

I took the liberty of adding a comment explaining why code to ignore
spurious interrupts was added. I also tweaked the change to input_-
interrupt() to more closely resemble the original code.

--jtc

2001-07-11 Greg McGary <greg@mcgary.org>

* gdbserver/remote-utils.c (remote_open): Set gdbserver as "owner"
of SIGIO.
(input_interrupt): Don't block on read, in case we got redundant
SIGIO. Don't gripe about redundant SIGIO.
* gdbserver/low-hppabsd.c (mywait): Use waitpid(). Enable SIGIO
handler while waiting.
* gdbserver/low-linux.c (mywait): Likewise.
* gdbserver/low-nbsd.c (mywait): Likewise.
* gdbserver/low-sparc.c (mywait): Likewise.

Index: gdbserver/low-hppabsd.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/low-hppabsd.c,v
retrieving revision 1.7
diff -c -r1.7 low-hppabsd.c
*** low-hppabsd.c 2001/04/06 22:25:09 1.7
--- low-hppabsd.c 2001/07/11 17:29:58
***************
*** 96,102 ****
int pid;
union wait w;

! pid = wait (&w);
if (pid != inferior_pid)
perror_with_name ("wait");

--- 96,104 ----
int pid;
union wait w;

! enable_async_io ();
! pid = waitpid (inferior_pid, &w, 0);
! disable_async_io ();
if (pid != inferior_pid)
perror_with_name ("wait");

Index: gdbserver/low-linux.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/low-linux.c,v
retrieving revision 1.9
diff -c -r1.9 low-linux.c
*** low-linux.c 2001/03/28 09:15:22 1.9
--- low-linux.c 2001/07/11 17:29:58
***************
*** 105,111 ****
int pid;
union wait w;

! pid = wait (&w);
if (pid != inferior_pid)
perror_with_name ("wait");

--- 105,113 ----
int pid;
union wait w;

! enable_async_io ();
! pid = waitpid (inferior_pid, &w, 0);
! disable_async_io ();
if (pid != inferior_pid)
perror_with_name ("wait");

Index: gdbserver/low-nbsd.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/low-nbsd.c,v
retrieving revision 1.9
diff -c -r1.9 low-nbsd.c
*** low-nbsd.c 2001/04/06 22:25:09 1.9
--- low-nbsd.c 2001/07/11 17:29:59
***************
*** 172,178 ****
int pid;
int w;

! pid = wait (&w);
if (pid != inferior_pid)
perror_with_name ("wait");

--- 172,180 ----
int pid;
int w;

! enable_async_io ();
! pid = waitpid (inferior_pid, &w, 0);
! disable_async_io ();
if (pid != inferior_pid)
perror_with_name ("wait");

Index: gdbserver/low-sparc.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/low-sparc.c,v
retrieving revision 1.6
diff -c -r1.6 low-sparc.c
*** low-sparc.c 2001/04/06 22:25:09 1.6
--- low-sparc.c 2001/07/11 17:29:59
***************
*** 102,108 ****
int pid;
union wait w;

! pid = wait (&w);
if (pid != inferior_pid)
perror_with_name ("wait");

--- 102,110 ----
int pid;
union wait w;

! enable_async_io ();
! pid = waitpid (inferior_pid, &w, 0);
! disable_async_io ();
if (pid != inferior_pid)
perror_with_name ("wait");

Index: gdbserver/remote-utils.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/remote-utils.c,v
retrieving revision 1.4
diff -c -r1.4 remote-utils.c
*** remote-utils.c 2001/03/06 08:21:44 1.4
--- remote-utils.c 2001/07/11 17:30:00
***************
*** 1,5 ****
/* Remote utility routines for the remote server for GDB.
! Copyright 1986, 1989, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
Free Software Foundation, Inc.

This file is part of GDB.
--- 1,5 ----
/* Remote utility routines for the remote server for GDB.
! Copyright 1986, 1989, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
Free Software Foundation, Inc.

This file is part of GDB.
***************
*** 32,37 ****
--- 32,39 ----
#include <sys/ioctl.h>
#include <signal.h>
#include <fcntl.h>
+ #include <sys/time.h>
+ #include <unistd.h>

int remote_debug = 0;
struct ui_file *gdb_stdlog;
***************
*** 156,163 ****
#if defined(F_SETFL) && defined (FASYNC)
save_fcntl_flags = fcntl (remote_desc, F_GETFL, 0);
fcntl (remote_desc, F_SETFL, save_fcntl_flags | FASYNC);
disable_async_io ();
- #endif /* FASYNC */
fprintf (stderr, "Remote debugging using %s\n", name);
}

--- 158,168 ----
#if defined(F_SETFL) && defined (FASYNC)
save_fcntl_flags = fcntl (remote_desc, F_GETFL, 0);
fcntl (remote_desc, F_SETFL, save_fcntl_flags | FASYNC);
+ #endif
+ #if defined (F_SETOWN)
+ fcntl (remote_desc, F_SETOWN, getpid ());
+ #endif
disable_async_io ();
fprintf (stderr, "Remote debugging using %s\n", name);
}

***************
*** 261,278 ****
static void
input_interrupt (void)
{
! int cc;
! char c;

! cc = read (remote_desc, &c, 1);

! if (cc != 1 || c != '\003')
{
! fprintf (stderr, "input_interrupt, cc = %d c = %d\n", cc, c);
! return;
! }

! kill (inferior_pid, SIGINT);
}

void
--- 266,294 ----
static void
input_interrupt (void)
{
! fd_set readset;
! struct timeval immediate = { 0, 0 };

! /* Protect against spurious interrupts. This has been observed to
! be a problem under NetBSD 1.4 and 1.5. */

! FD_ZERO (&readset);
! FD_SET (remote_desc, &readset);
! if (select (remote_desc + 1, &readset, 0, 0, &immediate) > 0)
{
! int cc;
! char c;
!
! cc = read (remote_desc, &c, 1);

! if (cc != 1 || c != '\003')
! {
! fprintf (stderr, "input_interrupt, cc = %d c = %d\n", cc, c);
! return;
! }
!
! kill (inferior_pid, SIGINT);
! }
}

void

--
J.T. Conklin
RedBack Networks