1

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.

2
  • What hardware? Which OS? Which version of Valgrind? Commented Dec 20, 2022 at 9:04
  • 1
    @PaulFloyd The issue has been resolved, but in case others encounter this issue, I'm running on a Debian GNU/Linux machine (bullseye) with valgrind package version 1:3.16.1-1. The shell I'm using is zsh, though the script is written in bash, which may be why the environment variable HOST didn't show up. Commented Dec 20, 2022 at 12:15

2 Answers 2

1

In order to determine the hostname, Valgrind and vgdb use the following rules

  1. Uses the HOST environment variable
  2. Uses the HOSTNAME environment variable
  3. If neither of the above are set, uses "???"
  4. If one of the environment variables was set and the hostname contains '/' then again "???" is used.

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Although the environment variable HOST seemed to be set in my shell, strangely GDB did not pick up on it. I was able to resolve it by simply adding HOST=<hostname> manually before my GDB command (even without ip netns exec). Thank you.
0

I had the same issue, however ??? appeared in a different spot:

Remote debugging using | vgdb
syscall failed: No such file or directory
error opening /tmp/vgdb-pipe-shared-mem-vgdb-<pid>-by-???-on-hostname shared memory file

On my system, the shared file was actually at /tmp/vgdb-pipe-shared-mem-vgdb-<pid>-by--on-hostname (no question marks), I found that by enabling -v -v on the valgrind command line invocation.

To fix this, I set export LOGNAME="" before the gdb invocation and that fixed it.

Originally, I found the fix in https://www.mail-archive.com/[email protected]/msg03487.html (apparently vgdb finds the user first via LOGNAME then USER and I guess none of those were set or were set to an incorrect value)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.