How to install Valgrind on macOS Mojave(10.14) with Homebrew?

前端 未结 10 1295
梦谈多话
梦谈多话 2020-12-04 08:58

I tried to install Valgrind with brew install Valgrind and got :

valgrind: This formula either does not compile or function as expected
on macOS         


        
10条回答
  •  南笙
    南笙 (楼主)
    2020-12-04 09:47

    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$

    • Using this gawk script, create the .supp valgrind file:

    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

提交回复
热议问题