From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22707 invoked by alias); 27 Jun 2011 17:10:43 -0000 Received: (qmail 22687 invoked by uid 22791); 27 Jun 2011 17:10:41 -0000 X-SWARE-Spam-Status: No, hits=0.4 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-ew0-f41.google.com (HELO mail-ew0-f41.google.com) (209.85.215.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 27 Jun 2011 17:10:20 +0000 Received: by ewy9 with SMTP id 9so1796987ewy.0 for ; Mon, 27 Jun 2011 10:10:19 -0700 (PDT) MIME-Version: 1.0 Received: by 10.14.17.30 with SMTP id i30mr2323164eei.243.1309194619167; Mon, 27 Jun 2011 10:10:19 -0700 (PDT) Received: by 10.14.29.11 with HTTP; Mon, 27 Jun 2011 10:10:19 -0700 (PDT) In-Reply-To: <20110627155425.GE20676@adacore.com> References: <20110627155425.GE20676@adacore.com> Date: Mon, 27 Jun 2011 17:10:00 -0000 Message-ID: Subject: Re: [patch] failed to attach to the same process after detaching in gdbserver multiprocess mode From: Liang Cheng To: Joel Brobecker Cc: gdb-patches@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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-06/txt/msg00404.txt.bz2 Thanks Joel, for your comments. This problem is that Linux_wait_for_event_1 does not return in linux_wait code path. So gdbserver stucks at linux-low.c::my_waitpid, and does not return OK/response to gdb. Source code level: old gdb resets lwp->stop_expected to 0 in linux-low.c::linux_attach if !non_stop, but 'pedro@codesourcery.com' removes these lines in version 1.134 of linux-low.c. Instead, he replaced it with 'thread_last_resume_kind =3D resume_stop', which is supposed to work. But as cross the different debug sessions on the same process (detach, q; and attach again in multiple process debug mode), cont_thread is saved and does not get reset at detaching. gdb server will use this stale 'cont_thread' to make a decision: resume the stopped process in the 2nd debug session. Thus, gdbserver does not get any chance of returning the call from linux_wait, while gdb waits for its response, until gdb tries 3 times of reading response. The fix is to reset the cont_thread so that gdbserver won't use stale states in multiple process mode. Hope above explanation is clear. Adding ChangeLog and fixing the format issue in comments. Feel free to make further adjustment on the comments or the log if necessary. Thanks Liang 2011-06-27 Liang Cheng * linux-low.c (linux_detach): Reset cont_thread. --- linux-low.c.orig 2011-05-04 15:20:12.000000000 -0500 +++ linux-low.c 2011-06-27 11:45:36.223194361 -0500 @@ -837,6 +837,9 @@ /* Since we presently can only stop all lwps of all processes, we need to unstop lwps of other processes. */ unstop_all_lwps (0, NULL); + + /* Reset cont_thread. */ + cont_thread =3D null_ptid; return 0; } On Mon, Jun 27, 2011 at 10:54 AM, Joel Brobecker wr= ote: > Liang, > > Thanks for sending these patches in. =A0I can't really approve your > patches since I don't have expertise in that area, but I can comment > on a couple of things: > =A0- It's great that you take the time to explain what the problem is; > =A0- Patches should have a ChangeLog entry to accompany them; > =A0- One nit: It's awesome that you take the time to add comments > =A0 =A0to document the code, and we don't use them often enough IMO. > =A0 =A0But I think that, in general, we want the comments in the code > =A0 =A0to say *why* you do what you do. =A0And oh, comments should start > =A0 =A0with a capital letter, and end with a period (and we always put > =A0 =A02 spaces after period, even before a closing */ > >> + >> + =A0/* reset cont_thread */ >> + =A0cont_thread =3D null_ptid; >> =A0 =A0return 0; > > -- > Joel >