This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] [gdbserver] Do not crash on file load without inferior


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
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.  */
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"
 	}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]