如何在需要超级用户权限的程序上运行 Valgrind? [英] How do I run Valgrind on a program that needs superuser permission?

查看:36
本文介绍了如何在需要超级用户权限的程序上运行 Valgrind?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 C 语言编写数据包嗅探器(使用 libpcap),但我无法使用 Valgrind 来查找程序中的内存泄漏,因为它必须以超级用户权限运行,因为如果没有这个,我什至无法打开用于捕获的网络接口.

I'm writing a packet sniffer in C (using libpcap) and I can't use Valgrind to find memory leaks in my program as it must be run with superuser permissions, because, without this, I can't even open the network interface for capture.

当我尝试使用 sudo 运行 Valgrind 时,我得到了这个:

When I try to run Valgrind with sudo, I got this:

$ valgrind sudo ./[exec]
==5211== 
==5211== Warning: Can't execute setuid/setgid/setcap executable: /usr/bin/sudo
==5211== Possible workaround: remove --trace-children=yes, if in effect
==5211== 
valgrind: /usr/bin/sudo: Permission denied

所以我尝试以超级用户身份运行(sudo su)并得到这个:

So I tried to run as superuser (sudo su) and got this:

# valgrind ./[exec]
valgrind: ./bin/TP2: Permission denied

还有:

$ sudo valgrind ./[exec]
valgrind: ./bin/TP2: Permission denied

我已经搜索了所有互联网来找到答案.

I've searched all the Internet to find an answer for that.

简而言之,我需要在我的数据包嗅探器中找到内存泄漏,并且它必须以管理员权限运行.有人可以帮我解决这个问题,或者至少推荐我另一个内存检查器吗?

In short, I need to find memory leaks in my packet sniffer and it must be run with admin permissions. Can someone help me with that or, at least, recommend me another memory checker, please?

推荐答案

我找到了解决方案.我不知道问题是因为我的可执行文件所在的卷是 NTFS 分区.首先,我将文件移动到 Ex4 分区上的一个随机文件夹,因此,我使用 chmod 更改了我的可执行文件的权限.

I found a solution. I had no clue that the problem were because the volume which my executable is placed on is a NTFS partition. First I moved the file to a random folder on a Ex4 partition, and so, I had changed permissions on my executable with chmod.

现在,当我以 root 身份登录时,我可以在我的程序上运行 Valgrind.

Now I can run Valgrind on my program when logged as root.

这篇关于如何在需要超级用户权限的程序上运行 Valgrind?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆