From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22729 invoked by alias); 13 Dec 2006 15:46:17 -0000 Received: (qmail 22703 invoked by uid 22791); 13 Dec 2006 15:46:15 -0000 X-Spam-Check-By: sourceware.org Received: from vir-del-01.spheriq.net (HELO vir-del-01.spheriq.net) (194.50.41.40) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 13 Dec 2006 15:46:00 +0000 Received: from vir-out-02.spheriq.net ([194.50.41.31]) by vir-del-01.spheriq.net with ESMTP id kBDFjvZA027701 for ; Wed, 13 Dec 2006 15:45:57 GMT Received: from vir-cus-02.spheriq.net (vir-cus-02.spheriq.net [194.50.41.86]) by vir-out-02.spheriq.net with ESMTP id kBDFjvP9018616 for ; Wed, 13 Dec 2006 15:45:57 GMT Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by vir-cus-02.spheriq.net with ESMTP id kBDFjtH8023928 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 13 Dec 2006 15:45:56 GMT Received: from zeta.dmz-eu.st.com (ns2.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id B2B78DA43 for ; Wed, 13 Dec 2006 15:45:54 +0000 (GMT) Received: from mail1.cro.st.com (mail1.cro.st.com [164.129.40.131]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 784B1474A9 for ; Wed, 13 Dec 2006 15:45:54 +0000 (GMT) Received: from [164.129.44.95] (crx595.cro.st.com [164.129.44.95]) by mail1.cro.st.com (MOS 3.5.8-GR) with ESMTP id CJF13969 (AUTH "denis pilat"); Wed, 13 Dec 2006 16:45:53 +0100 (CET) Message-ID: <45802031.2020402@st.com> Date: Wed, 13 Dec 2006 15:46:00 -0000 From: Denis PILAT User-Agent: Thunderbird 1.5.0.8 (X11/20061025) MIME-Version: 1.0 To: Denis PILAT , gdb-patches Subject: Re: gdbserver with reversed arguments goes into an infinite loop References: <457FCEB6.4060008@st.com> <20061213133737.GA2633@nevyn.them.org> In-Reply-To: <20061213133737.GA2633@nevyn.them.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2006-12/txt/msg00176.txt.bz2 Daniel Jacobowitz wrote: > On Wed, Dec 13, 2006 at 10:58:14AM +0100, Denis PILAT wrote: >> I've found that if you revert the argument of gdbserver, means writing >> the program's name before the COMM argument, it goes into an infinite >> loop, and as the CTRL+C does not work, you have to kill the process from >> an other shell. >> >> In gdbserver/server.c, the loop in question does the remote_open on the >> wrong passed argument (argv[1]) which unfortunately is the binary file >> you'd expect to open so remote_open does not exit on error. >> >> I think either we could check that we pass correct argument before using >> start_inferior(), this is executing before the loop. The bellow patch is >> in that sense. >> >> Or we find a way to exit the loop by adding a test in it. May be by >> adding something in remote_open to let it fail. > > I doubt it's in an infinite loop. It's probably sleeping, "waiting" > for a connection. We ought to allow C-c when no debugger is > connected yet. It'd be nice if remote_open wouldn't open ordinary > files, too. > Yes it's waiting for a connection but as arguments are wrongs it can wait for long ... You're right, preventing remote_open from opening ordinary files would exit the loop. 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 ! Here is a patch where I made a test to open only character device. If you right with that solution I'll propose a patch with a ChangeLog and so on. I took this opportunity to remove a warning on a strncpy() usage. 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 ? -- Denis Index: remote-utils.c =================================================================== --- remote-utils.c (revision 544) +++ remote-utils.c (working copy) @@ -36,6 +36,7 @@ #include #include #include +#include #ifndef HAVE_SOCKLEN_T typedef int socklen_t; @@ -68,10 +69,24 @@ void remote_open (char *name) { int save_fcntl_flags; - - if (!strchr (name, ':')) + char *port_str; + + port_str = strchr (name, ':'); + + /* if name is not of kind "HOST:PORT" it must be tty device. */ + if (!port_str) { - remote_desc = open (name, O_RDWR); + struct stat status; + int stat_result; + remote_desc = -1; + + /* Open only character device. */ + stat_result = stat(name, &status); + if (!stat_result && S_ISCHR(status.st_mode)) + { + remote_desc = open (name, O_RDWR); + } + if (remote_desc < 0) perror_with_name ("Could not open remote device"); @@ -123,14 +138,11 @@ remote_open (char *name) } else { - char *port_str; int port; struct sockaddr_in sockaddr; socklen_t tmp; int tmp_desc; - port_str = strchr (name, ':'); - port = atoi (port_str + 1); tmp_desc = socket (PF_INET, SOCK_STREAM, 0); @@ -650,7 +662,7 @@ prepare_resume_reply (char *buf, char st CORE_ADDR addr; int i; - strncpy (buf, "watch:", 6); + buf = strncpy (buf, "watch:", 6); buf += 6; addr = (*the_target->stopped_data_address) ();