2012-11-16 138 views
8

我使用valgrind 3.8.1和Mac OS 10.8.2 我使用Homebrew安裝了Valgrind。Valgrind支持Mac OS 10.8?

但是,當我嘗試在我的代碼上運行valgrind時,我從庫中得到了一大堆我甚至沒有用過的代碼中的錯誤。

valgrind --leak-check=full ./a.out 

==92079== 
==92079== HEAP SUMMARY: 
==92079==  in use at exit: 70,861 bytes in 362 blocks 
==92079== total heap usage: 529 allocs, 167 frees, 75,151 bytes allocated 
==92079== 
==92079== 16 bytes in 1 blocks are definitely lost in loss record 7 of 85 
==92079== at 0x54D7: malloc_zone_malloc (in /usr/local/Cellar/valgrind/3.8.1/lib/valgrind/vgpreload_memcheck-amd64-darwin.so) 
==92079== by 0x373381: recursive_mutex_init (in /usr/lib/libobjc.A.dylib) 
==92079== by 0x372025: _objc_init (in /usr/lib/libobjc.A.dylib) 
==92079== by 0xBB27: libSystem_initializer (in /usr/lib/libSystem.B.dylib) 
==92079== by 0x7FFF5FC13377: ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (in /usr/lib/dyld) 
==92079== by 0x7FFF5FC13761: ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (in /usr/lib/dyld) 
==92079== by 0x7FFF5FC1006D: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld) 
==92079== by 0x7FFF5FC0FFC3: ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld) 
==92079== by 0x7FFF5FC0FEB9: ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) (in /usr/lib/dyld) 
==92079== by 0x7FFF5FC01F9D: dyld::initializeMainExecutable() (in /usr/lib/dyld) 
==92079== by 0x7FFF5FC05B03: dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) (in /usr/lib/dyld) 
==92079== by 0x7FFF5FC01396: dyldbootstrap::start(macho_header const*, int, char const**, long, macho_header const*, unsigned long*) (in /usr/lib/dyld) 
..... 
..... 
..... 
..... 
==92079== 
==92079== LEAK SUMMARY: 
==92079== definitely lost: 16,816 bytes in 16 blocks 
==92079== indirectly lost: 1,168 bytes in 5 blocks 
==92079==  possibly lost: 4,941 bytes in 67 blocks 
==92079== still reachable: 47,936 bytes in 274 blocks 
==92079==   suppressed: 0 bytes in 0 blocks 
==92079== Reachable blocks (those to which a pointer was found) are not shown. 
==92079== To see them, rerun with: --leak-check=full --show-reachable=yes 
==92079== 
==92079== For counts of detected and suppressed errors, rerun with: -v 
==92079== ERROR SUMMARY: 21 errors from 21 contexts (suppressed: 0 from 0) 

任何人都可以展示如何抑制這些錯誤的Mac OS 10.8? (或只顯示我的代碼中的錯誤)

回答

2

valgrind v3.9.0解決了這個問題。儘管v3.9.0的官方發佈說明聲明支持Mac OSX 10.8已得到改進。但它似乎也可以在Mac OSX 10.9上正常工作。

你可以抓住在自制的最新版本:

brew update 
brew install valgrind 
2

對不起,這不會是你想要聽到的,你要是跑不過valgrind ./a.out 你應該看到沿

==18604== WARNING: Support on MacOS 10.8 is experimental and mostly broken. 
==18604== WARNING: Expect incorrect results, assertions and crashes. 
==18604== WARNING: In particular, Memcheck on 32-bit programs will fail to 
==18604== WARNING: detect any errors associated with heap-allocated data. 

即使線路輸出你壓制了你想壓制的東西,Valgrind很可能不會幫助你調試你的程序。 Xcode自帶內存分析工具,稱爲樂器,如果你喜歡使用它。