From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7885 invoked by alias); 18 Jul 2010 17:51:09 -0000 Mailing-List: contact archer-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: List-Id: Received: (qmail 7867 invoked by uid 22791); 18 Jul 2010 17:51:07 -0000 X-SWARE-Spam-Status: No, hits=-5.6 required=5.0 tests=AWL,BAYES_05,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Date: Sun, 18 Jul 2010 17:51:00 -0000 From: Oleg Nesterov To: Roland McGrath Cc: archer@sourceware.org Subject: Re: Q: mutlithreaded tracees && clone/exit Message-ID: <20100718174851.GA15528@redhat.com> References: <20100716205147.GA26313@redhat.com> <20100716213950.7A7BC40B45@magilla.sf.frob.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20100716213950.7A7BC40B45@magilla.sf.frob.com> User-Agent: Mutt/1.5.18 (2008-05-17) X-SW-Source: 2010-q3/txt/msg00033.txt.bz2 On 07/16, Roland McGrath wrote: > > > Q1: if gsbstub reported that the tracee has exited (say, we sent > > '$X09#..' to gdb), can gsbstub assume it can forget about this thread? > > I think so. In the ptrace-based implementation of gdbserver, it sends > X or W reports after it has done wait and gotten a death status. In > Linux, that means the zombie is reaped and its PID is available for reuse. Yes, but this doesn't necessarily mean gdbserver can forget its exit code (or some internal state), I do not see anything about this in docs. But yes, I think it can too. > > The main question is, I do not understand how gdbstub should handle the > > multithreaded targets. > > It's not really clear to me when gdb decides to ask for the thread > list. Never in my (limited) testing. > It looks like it only does it at extended-remote attach time if > you have set non-stop mode. OK, I'll check this. But this doesn't really matter. > > Q2: Shouldn't gdbstub let debugger know about sub-threads somehow? > > That's what I would expect in the abstract. But I know that gdb > didn't used to get new-thread notifications from ptrace either. It > looks like the linux-nat code does track PTRACE_EVENT_CLONE now. > But it may be that the gdbserver code and remote protocol were made > to match how things were when the native ptrace case didn't do that. gdbserver tracks PTRACE_EVENT_CLONE, yes. But it doesn't inform gdb. > gdb also uses higher-level knowledge read from user memory > (libthread_db) for some aspects of thread tracking. Well, yes and no (if I understood your message correctly). I have already looked at this code in horror. I really hope this magic is not needed for our purposes. It is gdbserver, not gdb, who uses libthread_db to find sub-threads and do other things. gdbserver asks gdb what is the symbol's address (say, _thread_db_list_t_next) via 'qSymbol'. > > I am asking because that I thought that gdb+gdbserver should > > try to work the same way as it works without gdbserver, and > > thus it should see clone/exit. > > I agree that's how it seems it should be. OK, so far it is not clear to me what should we do. If nothing else, I can replicate the gdbserver's behaviour. But imho it makes sense to do something more clever. However, there is the complication I already mentioned. If the main thread exits, this confuses gdbserver at least. It sends the "$T05" packets to gdb, then eventually gdb does vCont;c:pTGID.-1 and gdbserver doesn't work. It doesn't resume sub-threads, doesn't react to ^C, etc. I guess, gdbserver shouldn't send '$W' packet in this case, this can confuse gdb (but I didn't verify this yet). OTOH, it is not clear if gdbserver can delay this notification until all threads exit. Say, what should gdbserver do if gdb sends a private signal to the exited main thread? Or do something else which assumes it alive. Let's see what other experts think... Oleg.