This is the mail archive of the gdb@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]

gdb across PID namespaces


Hello,

I am using gdb to debug a process running in a different PID namespace
than gdb.  I am seeing that gdb cannot see child threads created
within the debugged process.  PID namespaces are described here:
http://lwn.net/Articles/532748/.  Here are the steps to reproduce the
problem:

$  g++ -o multi_threaded_program -pthread multi_threaded_program.cpp

$ ./run_in_new_pid_namespace ./multi_threaded_program&

$ sudo gdb ./multi_threaded_program
(gdb) attach 31493
(gdb) info threads
  Id   Target Id         Frame
* 1    process 31493 "multi_threaded_program" 0x00007f2ea316c148 in
pthread_join () from /lib/x86_64-linux-gnu/libpthread.so.0

When I run "multi_threaded_program" in the same PID namespace as gdb,
I see all the threads in the process on doing "info threads".

(gdb) info threads
  Id   Target Id         Frame
  4    Thread 0x7f971cadf700 (LWP 31560) "multi_threaded_program"
0x00007f971ce9b84d in nanosleep () from
/lib/x86_64-linux-gnu/libc.so.6
  3    Thread 0x7f971c2de700 (LWP 31561) "multi_threaded_program"
0x00007f971ce9b84d in nanosleep () from
/lib/x86_64-linux-gnu/libc.so.6
  2    Thread 0x7f971badd700 (LWP 31562) "multi_threaded_program"
0x00007f971ce9b84d in nanosleep () from
/lib/x86_64-linux-gnu/libc.so.6
* 1    Thread 0x7f971dad4740 (LWP 31555) "multi_threaded_program"
0x00007f971d1a4148 in pthread_join () from
/lib/x86_64-linux-gnu/libpthread.so.0

It appears that gdb is not able to correctly pick PIDs of threads
inside the child namespace, and perhaps for that reason, it's unable
to detect or show the threads.  Each thread in the child namespace has
multiple PIDs, one for each namespace from where it is visible.
Consider a thread T in the "child" namespace (where
multi_threaded_program is running).  Processes in the "parent"
namespace (e.g. gdb) will see a different PID for T than the PID that
processes in the child namespace (e.g. T itself) will see.

I'm wondering if this is a limitation of how gdb picks thread PIDs from ptrace.

Thanks,
Abhishek


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