From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1906 invoked by alias); 4 Mar 2011 21:37:49 -0000 Received: (qmail 1883 invoked by uid 22791); 4 Mar 2011 21:37:48 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 04 Mar 2011 21:37:42 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p24LbWVu024887 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 4 Mar 2011 16:37:32 -0500 Received: from host1.jankratochvil.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p24LbUdm020972 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 4 Mar 2011 16:37:31 -0500 Received: from host1.jankratochvil.net (localhost [127.0.0.1]) by host1.jankratochvil.net (8.14.4/8.14.4) with ESMTP id p24LbToU017590; Fri, 4 Mar 2011 22:37:29 +0100 Received: (from jkratoch@localhost) by host1.jankratochvil.net (8.14.4/8.14.4/Submit) id p24LbSOK017589; Fri, 4 Mar 2011 22:37:28 +0100 Date: Fri, 04 Mar 2011 21:37:00 -0000 From: Jan Kratochvil To: Pedro Alves Cc: Marc Khouzam , "'gdb-patches@sourceware.org'" Subject: Re: [patch] [gdbserver] Do not crash on file load without inferior Message-ID: <20110304213728.GA16487@host1.jankratochvil.net> References: <20110224114001.GA24673@host1.dyn.jankratochvil.net> <201102241242.49342.pedro@codesourcery.com> <201103042132.52768.pedro@codesourcery.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="Dxnq1zWXvFF0Q93v" Content-Disposition: inline In-Reply-To: <201103042132.52768.pedro@codesourcery.com> User-Agent: Mutt/1.5.21 (2010-09-15) 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: 2011-03/txt/msg00330.txt.bz2 --Dxnq1zWXvFF0Q93v Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1056 On Fri, 04 Mar 2011 22:32:52 +0100, Pedro Alves wrote: > On Friday 04 March 2011 21:24:51, Marc Khouzam wrote: > > > That sounds pretty bad. > > > > Any chance of getting a fix for this in the 7_2 branch? > > Which I gather would fix the problem Jan originally reported. > > Having to specify the 'file' before connecting to the target > > is a regression from previous versions of GDB and I was hoping > > not to have to special-case it in Eclipse :-) > > Indeed. I'll try getting to it soon if Jan doesn't. It > should be a one liner patch to gdb. That patch already IMO required a regression test. So far I never could do any gdbserver regression testing as gdbserver generates multiple gigabytes of: Remote side has terminated connection. GDBserver will reopen the connection. Can't open socket: Too many open files. I wrote some patches for it but I haven't yet got to posting them, the second one IIRC does not yet work. After making gdbserver regression testable I would like to get back to the original gdbserver problem. Thanks, Jan --Dxnq1zWXvFF0Q93v Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="p0.patch" Content-length: 1637 diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c index 88ef347..dd40014 100644 --- a/gdb/gdbserver/remote-utils.c +++ b/gdb/gdbserver/remote-utils.c @@ -321,7 +321,10 @@ remote_open (char *name) if (bind (listen_desc, (struct sockaddr *) &sockaddr, sizeof (sockaddr)) || listen (listen_desc, 1)) - perror_with_name ("Can't bind address"); + { + close (listen_desc); + perror_with_name ("Can't bind address"); + } /* If port is zero, a random port will be selected, and the fprintf below needs to know what port was selected. */ @@ -331,7 +334,10 @@ remote_open (char *name) if (getsockname (listen_desc, (struct sockaddr *) &sockaddr, &len) < 0 || len < sizeof (sockaddr)) - perror_with_name ("Can't determine port"); + { + close (listen_desc); + perror_with_name ("Can't determine port"); + } port = ntohs (sockaddr.sin_port); } diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c index 0ddf9de..b04a50d 100644 --- a/gdb/gdbserver/server.c +++ b/gdb/gdbserver/server.c @@ -2650,6 +2650,9 @@ main (int argc, char *argv[]) while (1) { + /* Wait a moment when for example the listening port is now busy. */ + int delay = 1; + noack_mode = 0; multi_process = 0; /* Be sure we're out of tfind mode. */ @@ -2665,7 +2668,11 @@ main (int argc, char *argv[]) write_enn (own_buf); putpkt (own_buf); } + + if (delay) + sleep (1); } + delay = 0; /* Wait for events. This will return when all event sources are removed from the event loop. */ --Dxnq1zWXvFF0Q93v Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="p1.patch" Content-length: 1608 diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c index b04a50d..76a027f 100644 --- a/gdb/gdbserver/server.c +++ b/gdb/gdbserver/server.c @@ -2312,7 +2312,8 @@ gdbserver_usage (FILE *stream) " --debug Enable general debugging output.\n" " --remote-debug Enable remote protocol debugging output.\n" " --version Display version information and exit.\n" - " --wrapper WRAPPER -- Run WRAPPER to start new programs.\n"); + " --wrapper WRAPPER -- Run WRAPPER to start new programs.\n" + " --once Exit after the first connection closed.\n"); if (REPORT_BUGS_TO[0] && stream == stdout) fprintf (stream, "Report bugs to \"%s\".\n", REPORT_BUGS_TO); } @@ -2536,6 +2537,8 @@ main (int argc, char *argv[]) } } } + else if (strcmp (*next_arg, "--once") == 0) + exit_requested = 1; else { fprintf (stderr, "Unknown argument: %s\n", *next_arg); diff --git a/gdb/testsuite/lib/gdbserver-support.exp b/gdb/testsuite/lib/gdbserver-support.exp index 3a098ae..c045c5f 100644 --- a/gdb/testsuite/lib/gdbserver-support.exp +++ b/gdb/testsuite/lib/gdbserver-support.exp @@ -218,10 +218,16 @@ proc gdbserver_start { options arguments } { # Fire off the debug agent. set gdbserver_command "$gdbserver" + + # GDB client could accidentally connect to a stale server. + append gdbserver_command " --once" + if { $options != "" } { append gdbserver_command " $options" } + append gdbserver_command " :$portnum" + if { $arguments != "" } { append gdbserver_command " $arguments" } --Dxnq1zWXvFF0Q93v--