vgdb:在进程网络命名空间中运行时“没有这样的文件或目录”共享内存文件

问题描述 投票:0回答:2

我正在尝试使用 Valgrind 和 GDB 调试程序。要在我的测试套件中运行该程序,它必须在网络命名空间内运行(使用

ip netns exec <namespace>
),因为它必须模拟不同的网络连接。要运行我想要调试的程序,我运行以下命令:

ip netns exec my-ns valgrind --leak-check=full --vgdb=yes --vgdb-error=0 <program> <args>

运行没有任何问题,但是当我尝试使用 GDB 连接时,出现以下错误:

(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.

我尝试在命名空间内和不在命名空间内运行 GDB 命令,如下所示,它们都给了我相同的错误:

gdb <binary>
ip netns exec my-ns gdb <binary>

/tmp
中查看VGDB生成的文件时,我发现以下内容:

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>

我以root身份运行所有命令,所以这里也不应该有权限问题。我还验证了在没有进程命名空间的情况下运行相同的进程没有问题 - 尽管这样我无法执行我的测试。另外,奇怪的是,当我在没有

ip netns exec
的情况下运行时,我在
/tmp
中得到以下文件,似乎没有获取我的主机名:

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-???'

感谢您的回复。

gdb valgrind gdbserver
2个回答
1
投票

为了确定主机名,Valgrind 和 vgdb 使用以下规则

  1. 使用HOST环境变量
  2. 使用HOSTNAME环境变量
  3. 如果以上均未设置,则使用“???”
  4. 如果设置了其中一个环境变量并且主机名包含“/”,则再次“???”已使用。

我不知道

ip netns exec
如何影响这些变量。也许你可以使用一个脚本,将 HOSTNAME 设置为 Valgrind 看到的任何内容,然后启动 gdb。


0
投票

我有同样的问题,但是

???
出现在不同的地方:

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

在我的系统上,共享文件实际上位于

/tmp/vgdb-pipe-shared-mem-vgdb-<pid>-by--on-hostname
(无问号),我发现通过在 valgrind 命令行调用上启用
-v -v

为了解决这个问题,我在

export LOGNAME=""
调用之前设置了
gdb
并修复了它。

最初,我在 https://www.mail-archive.com/[email protected]/msg03487.html 中找到了修复程序(显然 vgdb 首先通过

LOGNAME
然后通过
USER
找到用户,我猜这些都没有设置或设置为不正确的值)

© www.soinside.com 2019 - 2024. All rights reserved.