66

我尝试安装 Valgrindbrew install Valgrind并得到:

valgrind: This formula either does not compile or function as expected
on macOS versions newer than Sierra due to an upstream
incompatibility. 
Error: An unsatisfied requirement failed this build.

我试过了 brew install --HEAD Valgrind

相反,在成功安装依赖autoconfautomakelibtool,当它尝试安装 valgrind 时,我收到一个配置错误:

Valgrind works on Darwin 10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x and
17.x (Mac OS X 10.6/7/8/9/10/11 and macOS 10.12/13)

我的操作系统是 macOS Mojave(10.14),这是否意味着我目前无法使用 Homebrew 安装功能正常的 Valgrind?

4

10 回答 10

35
于 2019-02-22T01:51:46.113 回答
31

You may use Experimental Version of Valgrind for macOS 10.14.5 Mojave at:

https://github.com/sowson/valgrind

The command to use it is:

brew install --HEAD https://raw.githubusercontent.com/sowson/valgrind/master/valgrind.rb

It is still experimental and needs some work but for simple projects works already... Enjoy!

于 2019-07-01T07:14:50.357 回答
13

addition: I found this one worked for me on my OSX 10.14

brew install --HEAD https://raw.githubusercontent.com/LouisBrunner/valgrind-macos/master/valgrind.rb

A branch that is working to get OSX correct. something to tide us over until we get a real valgrind version fixed.

于 2019-07-29T21:44:15.667 回答
9

我有同样的问题。看来 valgrind 与最新的 macOS(10.14 Mojave)不兼容。尝试以 High Sierra 方式安装它(https://www.gungorbudak.com/blog/2018/04/28/how-to-install-valgrind-on-macos-high-sierra/)并获得与您描述的相同的输出. 我现在可以为您提供的唯一解决方案是使用虚拟机(https://www.virtualbox.org/)或使用 Docker(https://www.gungorbudak.com/blog/2018/06/13/memory -leak-testing-with-valgrind-on-macos-using-docker-containers/)。

于 2018-10-10T11:56:45.430 回答
6

I have just found a working solution to use VALGRIND on my Mac (Mojave 10.14.6). Just run this command :

brew install --HEAD https://raw.githubusercontent.com/LouisBrunner/valgrind-macos/master/valgrind.rb

(From https://github.com/LouisBrunner/valgrind-macos)

Hope it will work for you.

于 2019-09-01T19:27:22.933 回答
6

As others have mentioned, Louis Brunner maintains a working version at https://github.com/LouisBrunner/valgrind-macos.

brew tap LouisBrunner/valgrind
brew install --HEAD LouisBrunner/valgrind/valgrind

This worked for me for MacOS 10.15.7 Catalina.

于 2020-11-11T15:00:52.430 回答
2

对于 macOS 来说不是一个合适的解决方案,但我暂时创建了一个 docker 映像。在为 macOS 安装 docker 之后,这是启动 valgrind 的方法:

cd </path/to/source/directory/where/you/want/run/valgrind/with>
curl -O https://raw.githubusercontent.com/biocyberman/ValgrindDocker/master/startValgrind
./startValgrind # this will takes time for the first time, because it needs to fetch docker valgrind image
# you will get a root command prompt inside the docker image. 
# do what ever you want
# type 'exit' to quit
于 2018-12-16T20:00:49.647 回答
0

You can follow alex.m's answer to get valgrind, but if you'r using it on a int main() { return 0; } program, you'll get many weird errors, and non-existing allocs / free.

To 'hide' these annoying errors, you can follow theses steps (it's more a workaround than a real fix) (based on this wiki page and some research in Valgrind's source code):

  • First, create and compile a int main() { return 0; } program.
  • Execute the following command (to create file containing error suppression):

valgrind --leak-check=full --show-reachable=yes --error-limit=no --gen-supressions=all --log-file=$YOUR_LOG$ $YOUR_BINARY$

cat ./$YOUR_LOG$ | ./$YOUR_SCRIPT_FILE$ > minimal.supp

  • Copy and Past minimal.supp content at the end of $YOUR_VALGRIND_INSTALLATION_PATH$/lib/valgrind/default.supp file

And you are done! Weird and nonexistent errors will be ignored. If you also want's to remove the non-existing allocs, frees etc, you can directly edit Valgrind's source code. Or just use heapusage for leak-tracking

于 2019-03-22T14:47:42.233 回答
0

As of 2019-NOV-30, it is possible to build against OS X 10.14.6 via https://github.com/sowson/valgrind and https://github.com/LouisBrunner/valgrind-macos

However, there are many test failures (see the LouisBrunner link), noise during runs, and SEGVs when running against non-trivial programs: installing is, well, installing. YMMV.

于 2019-11-30T20:22:57.823 回答
0

(works on mojave 10.14.6)

brew install --HEAD https://raw.githubusercontent.com/sowson/valgrind/master/valgrind.rb
于 2020-10-17T17:07:36.593 回答