This is the mail archive of the
mailing list for the Archer project.
PATCH? gdb remote.c: readchar() should pop_target() ifSERIAL_ERROR?
- From: Oleg Nesterov <oleg at redhat dot com>
- To: Tom Tromey <tromey at redhat dot com>, Roland McGrath <roland at redhat dot com>, "Frank Ch. Eigler" <fche at redhat dot com>
- Cc: archer at sourceware dot org
- Date: Fri, 2 Jul 2010 03:13:02 +0200
- Subject: PATCH? gdb remote.c: readchar() should pop_target() ifSERIAL_ERROR?
I was trying to learn how gdb works with gdbserver and hit the bug.
The patch below seems to fix the problem for me but I am not sure
it is correct, I never looked into the (complex!) gdb sources before.
In short, sometimes gdb doing "target remote :tcp_port" refuses to
exit, putpkt_binary() complains that putpkt failed and longjmp()s
to the main loop. This happens sometimes if gdbserver dies.
A debugging session is active.
Inferior 1 [Remote target] will be killed.
Quit anyway? (y or n) y
putpkt: write failed: Broken pipe.
Not sure my analysis is correct, but I think that readchar() needs
a fix. A read/recv from a socket doesn't necessarily returns EOF if
the peer has closed the socket. It can return sock->sk_err set by
the previous send if the peer dies and sets sk->sk_shutdown.
The patch merely adds pop_target(). The more sophisticates fix
should probably continue the reading, sock->sk_err was cleared and
the socket may have the packets which we could read.
--- gdb-7.1/gdb/remote.c~ 2010-03-07 15:39:53.000000000 +0100
+++ gdb-7.1/gdb/remote.c 2010-07-02 02:38:09.000000000 +0200
@@ -6364,6 +6364,7 @@ readchar (int timeout)
error (_("Remote connection closed"));
/* no return */
+ pop_target ();
perror_with_name (_("Remote communication error"));
/* no return */