I'm trying to debug a program using Valgrind and GDB. To run the program in my test suite it has to be run within a network namespace (using ip netns exec <namespace>
), as it has to simulate different network connections. To run the program I want to debug I run the following command:
ip netns exec my-ns valgrind --leak-check=full --vgdb=yes --vgdb-error=0 <program> <args>
This runs without any problems, but when I try to connect using GDB I get the following error:
(gdb) target remote | vgdb
Remote debugging using | vgdb
syscall failed: No such file or directory
error opening /tmp/vgdb-pipe-shared-mem-vgdb-<pid>-by-root-on-??? shared memory file
Remote communication error. Target disconnected.: Connection reset by peer.
I've tried running the GDB command both within the namespace and without as follows, and they both give me the same error:
gdb <binary>
ip netns exec my-ns gdb <binary>
When looking at the files generated by VGDB in /tmp
I find the following:
prw------- 1 root root 0 Dec 20 08:31 vgdb-pipe-from-vgdb-to-<pid>-by-root-on-<hostname>
-rw------- 1 root root 48 Dec 20 08:31 vgdb-pipe-shared-mem-vgdb-<pid>-by-root-on-<hostname>
prw------- 1 root root 0 Dec 20 08:31 vgdb-pipe-to-vgdb-from-<pid>-by-root-on-<hostname>
I am running all commands as root, so there should be no permissions problems here either. I have also verified that there is no problem running the same process without the process namespace - although then I am unable to perform my tests. Also, curiously enough, when I run without ip netns exec
I get the following files in /tmp
, not seeming to pick up my hostname:
prw------- 1 root root 0 Dec 20 08:44 'vgdb-pipe-from-vgdb-to-<pid>-by-root-on-???'
-rw------- 1 root root 48 Dec 20 08:44 'vgdb-pipe-shared-mem-vgdb-<pid>-by-root-on-???'
prw------- 1 root root 0 Dec 20 08:44 'vgdb-pipe-to-vgdb-from-<pid>-by-root-on-???'
I appreciate your replies.
In order to determine the hostname, Valgrind and vgdb use the following rules
I don't know how ip netns exec
affects such variables. Maybe you can use a script that sets HOSTNAME to whatever Valgrind is seeing and then starts gdb.