From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4323 invoked by alias); 2 Jul 2010 01:14:57 -0000 Mailing-List: contact archer-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: List-Id: Received: (qmail 4311 invoked by uid 22791); 2 Jul 2010 01:14:56 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Date: Fri, 02 Jul 2010 01:14:00 -0000 From: Oleg Nesterov To: Tom Tromey , Roland McGrath , "Frank Ch. Eigler" Cc: archer@sourceware.org Subject: PATCH? gdb remote.c: readchar() should pop_target() if SERIAL_ERROR? Message-ID: <20100702011302.GA24599@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) X-SW-Source: 2010-q3/txt/msg00000.txt.bz2 Hello. 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. (gdb) q A debugging session is active. Inferior 1 [Remote target] will be killed. Quit anyway? (y or n) y putpkt: write failed: Broken pipe. (gdb) 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. Oleg. --- 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 */ case SERIAL_ERROR: + pop_target (); perror_with_name (_("Remote communication error")); /* no return */ case SERIAL_TIMEOUT: