public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: archer@sourceware.org
Subject: Re: Q: mutlithreaded tracees && clone/exit
Date: Mon, 19 Jul 2010 16:01:00 -0000	[thread overview]
Message-ID: <20100719160127.GA13331@host1.dyn.jankratochvil.net> (raw)
In-Reply-To: <20100718174851.GA15528@redhat.com> <20100716205147.GA26313@redhat.com>

On Fri, 16 Jul 2010 22:51:47 +0200, Oleg Nesterov wrote:
> In case this matters, I used gdb-7.1 for testing.

FSF GDB (not Fedora/RHEL GDB) probably.


> Q1: if gsbstub reported that the tracee has exited (say, we sent
> '$X09#..' to gdb), can gsbstub assume it can forget about this thread?

`X' is about processes, not threads ('W'=TARGET_WAITKIND_EXITED,
'X'=TARGET_WAITKIND_SIGNALLED).

Threads death is handled by GDB-driven 'T' packet (remote_thread_alive).

(I just mostly read the GDB sources, I am intact by the remote GDB stuff.)


> I mean, can it assume that gdb won't send something like 'D;EXITED_PID'?

TARGET_WAITKIND_EXITED and TARGET_WAITKIND_SIGNALLED in
handle_inferior_event() call target_mourn_inferior(), this is very terminal.


> Looking at gdb sources/behaviour, I think the answer is yes, it can
> forget. But I'd like to have the confirmation.

Yes, I also think so.  I cannot give the confirmation.


> And. I'd like to let you know that gdb is buggy ;)

Please file those bugs while discussing them here:
	http://sourceware.org/bugzilla/enter_bug.cgi?product=gdb


> The user presses ^C, gdb sends 3 and waits for reply. Suppose that
> gdbstub doesn't reply immediately.

IMHO this remote GDB protocol and non-stop mode are primarily tested with
Eclipse-over-MI.  Bugs faced by GDB CLI are going to be very common.


> I noticed this bug when I found another problem, gdb+gdbserver doesn't
> work correctly if the main thread  exits. But let's forget about this
> problem for now.

This issue does not work well even with linux-nat.c (local GDB), in the
current development stage of ugdb I believe we do not have to solve it before
linux-nat.c gets fixed first:
	GDB hangs with simple multi-threaded program on linux
	http://sourceware.org/ml/gdb/2010-07/msg00045.html


> The main question is, I do not understand how gdbstub should handle the
> multithreaded targets.
[...]
> 	(gdb) file test1
> 	(gdb) target extended-remote :2000
> 	(gdb) attach 16927
> 	Attached to process 16927
> 	...
> 	0x00000033af60e57d in pause () from /lib64/libpthread.so.0
> 	(gdb)
> 
> OK. gdbserver ptraces both threads. But afaics gdb doesn't now this
> program is multithreaded,

> Q2: Shouldn't gdbstub let debugger know about sub-threads somehow?

gdb did not ask for it so why gdbserver should tell gdbserver it?

(gdb) info threads 
[New Thread 14739.14740] <-- GDB has notified it now.
  2 Thread 14739.14740  0x000000349e8a6a6d in nanosleep () at ../sysdeps/unix/syscall-template.S:82
* 1 Thread 14739.14739  0x000000349f007fbd in pthread_join (threadid=140515741927184, thread_return=0x0) at pthread_join.c:89

Eclipse apparently does `info threads' over MI so it is not a problem.
Also as you state in non-stop mode gdb asks for the thread list anyway.


> gdbserver resumes both threads. Press enter, the sub-thread exits.
> 
> And nothing happens! gdbserver sends nothing to gdb, it just reaps
> the tracee silently:
...
> Q3: is it correct? shouldn't we inform the debugger?

GDB will sooner or later use the 'T' packet (remote_thread_alive) to reclaim
dead threads.

With libpthread_db (linux-thread-db.c) it just sets
thread_info->private->dying = 1; on TD_DEATH anyway and continues tracking the
threads before its kernel task finally dies.


> So. Afaics, gdb can only find the new thread if the user does
> "info threads", or if this thread reports somehow about itself
> (say, it gets a signal and gdbserver sends "$T..." with its tid).

Yes, GDB is master of the remote protocol communication.  Not the gdbserver.


> Also. gdb can't know the sub-thread has exited unless the user
> does "info threads" again, or something like "$TpPID.TGID" gets
> "E01" in reply.
> 
> Correct?
> 
> Q4: is this what we want to implement?

IMO yes, we should first get ugdb a bit on-par with linux-nat.c, don't we?


> 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.

GDB has two lists of "threads":

Real libpthread / libthread_db / linux-thread-db.c / struct thread_info *
which is primarily used.  Name is displayed by thread_db_pid_to_str().

Then there are also kernel tasks / linux-nat.c / struct lwp_info * which are
provided when libthread_db is not available.  This second category IIRC does
not work so well as linux-thread-db.c is more commonly in use (I do not have
a fail testcase offhand, it may work).  Name is displayed by
linux_nat_pid_to_str().

Both types of "threads" are displayed by GDB CLI `info threads'.  Their name
format differs a bit, according to the display name function (to_pid_to_str).


> However, gdbserver sends nothing to gdb if the tracee does
> pthread_create() or pthread_exit().

yes


On Sun, 18 Jul 2010 19:48:51 +0200, Oleg Nesterov wrote:
> gdbserver tracks PTRACE_EVENT_CLONE, yes. But it doesn't inform gdb.

IMO we can tune the non-libpthread mode later, AFAIK it does not work well
with linux-nat.c anyway.


> > 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 see this can be a problem for ugdb.  Guessing we will need to change GDB to
support new variant of proc-service.c working over the GDB protocol wire.


> However, there is the complication I already mentioned. If the main
> thread exits, this confuses gdbserver at least.

Replied above, this is a GDB bug even with linux-nat.c first, it was fixed in
Fedora GDB before but for some cases it apparently still does not work.


Thanks,
Jan

  parent reply	other threads:[~2010-07-19 16:01 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-16 20:54 Oleg Nesterov
2010-07-16 21:40 ` Roland McGrath
2010-07-18 17:51   ` Oleg Nesterov
2010-07-18 18:04     ` Oleg Nesterov
2010-07-18 20:22     ` Roland McGrath
2010-07-19 13:44 ` BUG: add_thread_silent()->switch_to_thread(minus_one_ptid) is wrong Oleg Nesterov
2010-07-19 15:36   ` Oleg Nesterov
2010-07-19 16:01 ` Jan Kratochvil [this message]
2010-07-19 22:57   ` Q: mutlithreaded tracees && clone/exit Roland McGrath
2010-07-20 13:18   ` Oleg Nesterov
2010-07-20 14:04     ` BUG? gdb, non-stop && c -a Oleg Nesterov
2010-07-20 14:12       ` Jan Kratochvil
2010-07-20 14:49         ` Oleg Nesterov
2010-07-20 15:08           ` Jan Kratochvil
2010-07-20 15:28             ` Oleg Nesterov
2010-07-20 19:43         ` Roland McGrath
2010-07-21  7:59           ` Oleg Nesterov
2010-07-21  8:10             ` Jan Kratochvil
2010-07-21 11:12               ` Oleg Nesterov
2010-07-20 14:21     ` Q: mutlithreaded tracees && clone/exit Jan Kratochvil
2010-07-20 15:09       ` Oleg Nesterov
2010-07-20 19:41     ` Roland McGrath
2010-07-21  8:32       ` Oleg Nesterov
2010-07-20 14:43 ` Q: who maintains the STOPPED/RUNNING state? Oleg Nesterov
     [not found]   ` <y0mk4ophmvn.fsf@fche.csb>
2010-07-21 10:20     ` Oleg Nesterov
2010-07-21 10:51       ` Oleg Nesterov
2010-07-21 17:06 ` Q: multiple inferiors, all-stop && vCont Oleg Nesterov
2010-07-21 20:42   ` Roland McGrath
2010-07-23 17:33     ` Oleg Nesterov
2010-07-26 14:30       ` Oleg Nesterov
2010-07-26 16:06         ` Oleg Nesterov
2010-07-28 18:19         ` gdbstub initial code, another approach Oleg Nesterov
2010-07-29 21:38           ` Frank Ch. Eigler
2010-07-30 13:00             ` Oleg Nesterov
2010-07-30 13:16               ` Frank Ch. Eigler
2010-07-30 15:01                 ` Oleg Nesterov
2010-07-30 13:25               ` Jan Kratochvil
2010-07-30 14:44                 ` Oleg Nesterov
2010-07-30 15:20                   ` Jan Kratochvil
2010-08-02 12:54                     ` Oleg Nesterov
2010-08-03 13:55                       ` Jan Kratochvil
2010-07-30 17:59                 ` Tom Tromey
2010-08-02 18:25           ` Oleg Nesterov
2010-08-02 23:54           ` Jan Kratochvil
2010-08-03 12:27             ` Q: %Stop && gdb crash Oleg Nesterov
2010-08-03 13:17               ` Oleg Nesterov
2010-08-03 19:57                 ` Kevin Buettner
2010-08-04 19:42                   ` Oleg Nesterov
2010-08-04 23:32                     ` Kevin Buettner
2010-08-05 18:24                       ` Oleg Nesterov
2010-08-03 13:36               ` Jan Kratochvil
2010-08-03 15:09                 ` Oleg Nesterov
2010-08-03 12:39         ` Q: multiple inferiors, all-stop && vCont Jan Kratochvil
2010-08-03 14:32           ` Oleg Nesterov
2010-08-03 15:55             ` Jan Kratochvil
2010-08-03 16:56               ` Oleg Nesterov
2010-08-03 18:37                 ` Jan Kratochvil
2010-08-18 17:07           ` Jan Kratochvil
2010-08-18 19:22             ` Roland McGrath

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100719160127.GA13331@host1.dyn.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=archer@sourceware.org \
    --cc=oleg@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).