public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug server/16255] New: gdbserver cannot attach to a second inferior that is multi-threaded
@ 2013-11-26 15:34 marc.khouzam at ericsson dot com
2014-03-26 17:09 ` [Bug server/16255] " simon.marchi at polymtl dot ca
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: marc.khouzam at ericsson dot com @ 2013-11-26 15:34 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=16255
Bug ID: 16255
Summary: gdbserver cannot attach to a second inferior that is
multi-threaded
Product: gdb
Version: 7.4
Status: NEW
Severity: normal
Priority: P2
Component: server
Assignee: unassigned at sourceware dot org
Reporter: marc.khouzam at ericsson dot com
This problem was not happening in version 7.3, but starts with 7.4. I'm
running on Ubuntu 11.10 but we've seen it on Ubuntu 12.04 and even on a very
old SLED 10 machine.
When debugging with gdbserver, if I try to attach to a second process and that
process is multi-threaded, gdbserver will fail to attach to any thread beyond
the first one with repeating error:
Cannot attach to lwp 13779: Operation not permitted (1)
Cannot attach to lwp 13779: Operation not permitted (1)
Cannot attach to lwp 13779: Operation not permitted (1)
Cannot attach to lwp 13779: Operation not permitted (1)
Cannot attach to lwp 13779: Operation not permitted (1)
Cannot attach to lwp 13779: Operation not permitted (1)
Cannot attach to lwp 13779: Operation not permitted (1)
[forever and very fast]
The problem only happens with gdbserver, local attach works ok.
The problem only happens when attaching, starting a second new multi-threaded
process from GDB works ok.
Attaching to a second process, if that process in single-threaded, does work.
In fact, attaching to a second process with a single thread works, even if that
process then creates new threads after the attach.
To reproduce:
1- start two instances of a long running multi-threaded binary from a shell
2- start gdbserver: gdbserver --multi :9999
4- debug with gdb:
> gdb.7.7 /home/lmckhou/testing/multithread
GNU gdb (GDB) 7.6.50.20131126-cvs
Reading symbols from /home/lmckhou/testing/multithread...done.
(gdb) l
3
4 void *thread_exec(void *p) {
5 for (int i=0;i<500;i++) {
6 sleep(1);
7 }
8 }
9
10 int main() {
11 pthread_t thread2;
12 int iret2 = pthread_create(&thread2, NULL, thread_exec, (void*)
"Thread 2");
13 pthread_join(thread2, NULL);
14 return 0;
15 }
16
(gdb) set target-async on
(gdb) set non-stop on
(gdb) set pagination off
(gdb) add-inferior -exec /home/lmckhou/testing/multithread
Added inferior 2
Reading symbols from /home/lmckhou/testing/multithread...done.
(gdb) tar ext :9999
Remote debugging using :9999
(gdb) attach 13896
Attaching to program: /home/lmckhou/testing/multithread, process 13896
[New Thread 13896.13896]
[New Thread 13896.13898]
(gdb) inferior 2
[Switching to inferior 2 [<null>] (/home/lmckhou/testing/multithread)]
=== The first inferior could have been single threaded too ===
=== Now we will attach to another multi-threaded process ===
(gdb) attach 13897
Attaching to program: /home/lmckhou/testing/multithread, process 13897
=== here gdbserver goes crazy printing the error message: ===
=== "Cannot attach to lwp 13779: Operation not permitted (1)" ===
=== after some delay, we see gdb printing: ===
Ignoring packet error, continuing...
Attaching to process 13897 failed with: timeout
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug server/16255] gdbserver cannot attach to a second inferior that is multi-threaded
2013-11-26 15:34 [Bug server/16255] New: gdbserver cannot attach to a second inferior that is multi-threaded marc.khouzam at ericsson dot com
@ 2014-03-26 17:09 ` simon.marchi at polymtl dot ca
2014-03-31 18:51 ` simon.marchi at polymtl dot ca
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: simon.marchi at polymtl dot ca @ 2014-03-26 17:09 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=16255
Simon Marchi <simon.marchi at polymtl dot ca> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |simon.marchi at polymtl dot ca
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug server/16255] gdbserver cannot attach to a second inferior that is multi-threaded
2013-11-26 15:34 [Bug server/16255] New: gdbserver cannot attach to a second inferior that is multi-threaded marc.khouzam at ericsson dot com
2014-03-26 17:09 ` [Bug server/16255] " simon.marchi at polymtl dot ca
@ 2014-03-31 18:51 ` simon.marchi at polymtl dot ca
2014-04-25 18:24 ` cvs-commit at gcc dot gnu.org
2014-04-25 18:26 ` palves at redhat dot com
3 siblings, 0 replies; 5+ messages in thread
From: simon.marchi at polymtl dot ca @ 2014-03-31 18:51 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=16255
--- Comment #1 from Simon Marchi <simon.marchi at polymtl dot ca> ---
Ok, the problem is that a ptid with a wrong value is built when we attach the
subsequent threads.
See:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gdb/gdbserver/linux-low.c;hb=HEAD#l673
For the pid field, we use the pid of current_inferior. When attaching to the
second inferior, current_inferior is never set to the newly created inferior,
it still points to the first one. Therefore, ptids of the threads of the second
inferior are created with the pid of the first.
One solution is to temporarily switch current_inferior in linux_attach when
attaching the subsequent threads.
Another would be to change the line
ptid = ptid_build (pid, lwpid, 0);
for
ptid = ptid_build (linux_proc_get_tgid (lwpid), lwpid, 0);
which will go read the pid (tgid) in /proc.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug server/16255] gdbserver cannot attach to a second inferior that is multi-threaded
2013-11-26 15:34 [Bug server/16255] New: gdbserver cannot attach to a second inferior that is multi-threaded marc.khouzam at ericsson dot com
2014-03-26 17:09 ` [Bug server/16255] " simon.marchi at polymtl dot ca
2014-03-31 18:51 ` simon.marchi at polymtl dot ca
@ 2014-04-25 18:24 ` cvs-commit at gcc dot gnu.org
2014-04-25 18:26 ` palves at redhat dot com
3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2014-04-25 18:24 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=16255
--- Comment #3 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gdb and binutils".
The branch, master has been updated
via 94611da2409673314d7caaf38c66baa52d6f5adc (commit)
from 7ae1a6a6ccda41aa8bbe9adb0f7fcde8bf8d5cb3 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=94611da2409673314d7caaf38c66baa52d6f5adc
commit 94611da2409673314d7caaf38c66baa52d6f5adc
Author: Pedro Alves <palves@redhat.com>
Date: Fri Apr 25 19:22:27 2014 +0100
Add missing gdbserver/ChangeLog entry for previous commit.
2014-04-25 Pedro Alves <palves@redhat.com>
PR server/16255
* linux-low.c (linux_attach_fail_reason_string): New function.
(linux_attach_lwp): Delete.
(linux_attach_lwp_1): Rename to ...
(linux_attach_lwp): ... this. Take a ptid instead of a pid as
argument. Remove "initial" parameter. Return int instead of
void. Don't error or warn here.
(linux_attach): Adjust to call linux_attach_lwp. Call error on
failure to attach to the tgid. Call warning when failing to
attach to an lwp.
* linux-low.h (linux_attach_lwp): Take a ptid instead of a pid as
argument. Remove "initial" parameter. Return int instead of
void. Don't error or warn here.
(linux_attach_fail_reason_string): New declaration.
* thread-db.c (attach_thread): Adjust to linux_attach_lwp's
interface change. Use linux_attach_fail_reason_string.
-----------------------------------------------------------------------
Summary of changes:
gdb/gdbserver/ChangeLog | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug server/16255] gdbserver cannot attach to a second inferior that is multi-threaded
2013-11-26 15:34 [Bug server/16255] New: gdbserver cannot attach to a second inferior that is multi-threaded marc.khouzam at ericsson dot com
` (2 preceding siblings ...)
2014-04-25 18:24 ` cvs-commit at gcc dot gnu.org
@ 2014-04-25 18:26 ` palves at redhat dot com
3 siblings, 0 replies; 5+ messages in thread
From: palves at redhat dot com @ 2014-04-25 18:26 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=16255
Pedro Alves <palves at redhat dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
Target Milestone|--- |7.8
--- Comment #4 from Pedro Alves <palves at redhat dot com> ---
Fixed.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-04-25 18:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-26 15:34 [Bug server/16255] New: gdbserver cannot attach to a second inferior that is multi-threaded marc.khouzam at ericsson dot com
2014-03-26 17:09 ` [Bug server/16255] " simon.marchi at polymtl dot ca
2014-03-31 18:51 ` simon.marchi at polymtl dot ca
2014-04-25 18:24 ` cvs-commit at gcc dot gnu.org
2014-04-25 18:26 ` palves at redhat dot com
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).