This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug server/16255] New: gdbserver cannot attach to a second inferior that is multi-threaded


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]