Re: gdbserver with reversed arguments goes into an infinite loop

Daniel Jacobowitz
2006-12-30T15:45:40Z

On Wed, Dec 13, 2006 at 04:45:53PM +0100, Denis PILAT wrote:
> But may be it would be better to open only character device (S_ISCHR
> macro) than excluding ordinary files (S_ISREG macro). It's up to you !

Good idea. FIFOs are OK too. I've committed a nicer version of this.

> I took this opportunity to remove a warning on a strncpy() usage.

Why did it warn? I omitted this bit, because I don't see any reason
(or any warning).

> I'm wondering about the compilation of this code under windows. I never
> compiled a gdbserver on windows, is there any gdbserver hosted under
> windows ?

If you were working against HEAD, you'd see that there was now - but
we don't support serial ports there, so it's not a problem. It's all
#ifdef'd out.

--
Daniel Jacobowitz
CodeSourcery

2006-12-30 Denis PILAT <denis.pilat@st.com>
Daniel Jacobowitz <dan@codesourcery.com>

* remote-utils.c (remote_open): Check the type of specified
serial port devices before opening them.
* server.c (main): Kill the inferior if an error occurs during
the first remote_open.

Index: remote-utils.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/remote-utils.c,v
retrieving revision 1.34
diff -u -p -r1.34 remote-utils.c
--- remote-utils.c 16 Nov 2006 15:08:25 -0000 1.34
+++ remote-utils.c 30 Dec 2006 15:23:37 -0000
@@ -52,6 +52,8 @@
#if HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
+#include <sys/stat.h>
+#include <errno.h>

#if USE_WIN32API
#include <winsock.h>
@@ -94,13 +96,25 @@ remote_open (char *name)
#if defined(F_SETFL) && defined (FASYNC)
int save_fcntl_flags;
#endif
-
- if (!strchr (name, ':'))
+ char *port_str;
+
+ port_str = strchr (name, ':');
+ if (port_str == NULL)
{
#ifdef USE_WIN32API
error ("Only <host>:<port> is supported on this platform.");
#else
- remote_desc = open (name, O_RDWR);
+ struct stat statbuf;
+
+ if (stat (name, &statbuf) == 0
+ && (S_ISCHR (statbuf.st_mode) || S_ISFIFO (statbuf.st_mode)))
+ remote_desc = open (name, O_RDWR);
+ else
+ {
+ errno = EINVAL;
+ remote_desc = -1;
+ }
+
if (remote_desc < 0)
perror_with_name ("Could not open remote device");

Index: server.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/server.c,v
retrieving revision 1.42
diff -u -p -r1.42 server.c
--- server.c 16 Nov 2006 15:08:25 -0000 1.42
+++ server.c 30 Dec 2006 15:23:37 -0000
@@ -614,6 +614,13 @@ main (int argc, char *argv[])
}
}

+ if (setjmp (toplevel))
+ {
+ fprintf (stderr, "Killing inferior\n");
+ kill_inferior ();
+ exit (1);
+ }
+
while (1)
{
remote_open (argv[1]);