Sample Header Ad - 728x90

Attach gdb from a docker container to a process running in a different PID namespace

0 votes
1 answer
399 views
I built a docker image with gcc binutils and gdb debugger installed inside. I would attach gdb from that docker container to a process inside a lxc container running on the same Linux host. The lxc container uses its own PID namespace, therefore gdb running in the docker container complains that target process and debugger are not in the same PID namespace. [SR-PCE-251:~]$ docker run -it --pid host --rm --cap-add=SYS_PTRACE --security-opt seccomp=unconfined carlo/ubuntu root@e7b2db23af34:/# root@e7b2db23af34:/# id uid=0(root) gid=0(root) groups=0(root) root@e7b2db23af34:/# root@e7b2db23af34:/# gdb -q attach 11365 attach: No such file or directory. Attaching to process 11365 [New LWP 24283] [New LWP 20025] [New LWP 20024] [New LWP 19992] [New LWP 19991] [New LWP 13974] [New LWP 13970] [New LWP 13969] [New LWP 13968] [New LWP 13967] [New LWP 13962] [New LWP 13958] [New LWP 13957] [New LWP 13954] [New LWP 13952] [New LWP 13944] [New LWP 12078] [New LWP 11822] [New LWP 11543] [New LWP 11515] [New LWP 11489] [New LWP 11483] [New LWP 11482] [New LWP 11477] [New LWP 11476] warning: "target:/proc/11365/exe": could not open as an executable file: Operation not permitted. warning: `target:/proc/11365/exe': can't open to read symbols: Operation not permitted. warning: Could not load vsyscall page because no executable was specified warning: Target and debugger are in different PID namespaces; thread lists and other data are likely unreliable. Connect to gdbserver inside the container. 0x00007f0bf997ac73 in ?? () (gdb) Edited to provide more information based on comments received [host:/gdb-install]$ id uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 [host:/gdb-install]$ [host:/gdb-install]$ ls -la total 24 drwxrwxr-x. 6 1000 1000 4096 Nov 14 09:32 . drwxr-xr-x. 30 root root 4096 Nov 14 11:27 .. drwxrwxr-x. 2 1000 1000 4096 Nov 14 09:32 bin drwxrwxr-x. 3 1000 1000 4096 Nov 14 09:32 include drwxrwxr-x. 2 1000 1000 4096 Nov 14 09:32 lib drwxrwxr-x. 6 1000 1000 4096 Nov 14 09:32 share [host:/gdb-install]$ [host:/gdb-install]$ export LD_LIBRARY_PATH=/gdb-install/bin:/gdb-install/lib [host:/gdb-install]$ ./bin/gdb ./bin/gdb: error while loading shared libraries: libmpfr.so.6: cannot open shared object file: No such file or directory [host:/gdb-install]$
Asked by CarloC (385 rep)
Nov 13, 2024, 08:43 AM
Last activity: Nov 20, 2024, 05:54 PM