日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 综合教程 >内容正文

综合教程

linux 下内存检查工具 valgrind 及 sanitizer 编译选项及静态检查工具

發(fā)布時(shí)間:2023/12/15 综合教程 61 生活家
生活随笔 收集整理的這篇文章主要介紹了 linux 下内存检查工具 valgrind 及 sanitizer 编译选项及静态检查工具 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

要記住,這兩個(gè)工具都是動(dòng)態(tài)檢查工具,也就是程序運(yùn)行時(shí)覆蓋到的代碼才會(huì)被檢查,未覆蓋的代碼是不會(huì)檢查的。

valgrind是一個(gè)模擬程序運(yùn)行環(huán)境并記錄程序非法內(nèi)存使用的一個(gè)程序工具。可能慢一些,因?yàn)槭峭獠磕M。Valgrind慢,像調(diào)試器一樣,它無(wú)法擴(kuò)展。如果您要處理大型數(shù)據(jù)集,則可能會(huì)花費(fèi)很長(zhǎng)時(shí)間,人們經(jīng)常不理會(huì)“執(zhí)行時(shí)間”,如果您處理小問題則可以不關(guān)心,但是性能是生活質(zhì)量的基本要素,我認(rèn)為您不應(yīng)或不能在模擬的生產(chǎn)環(huán)境中運(yùn)行valgrind。

sanitizer是google開發(fā)的一個(gè)編譯工具集(編譯選項(xiàng)),最初為llvm開發(fā),后來(lái)gcc(g++) 4.9版及更新版也集成了這個(gè)編譯工具。可能快一些,因?yàn)橹苯泳幾g進(jìn)去了。sanitizer更精細(xì)精確,因?yàn)橛泻芏噙x項(xiàng)可以開關(guān),但正因?yàn)槭蔷幾g選項(xiàng),因此很多時(shí)候環(huán)境無(wú)法讓你使用sanitizer,最主要是編譯器不允許。

兩個(gè)都好用。

1 sanitizer

如果系統(tǒng)里面無(wú)法直接安裝valgrind,則可以考慮使用sanitizer 來(lái)進(jìn)行調(diào)試。為了更好的調(diào)試,系統(tǒng)里可能需要安裝libasan 庫(kù)(特別是使用Address Sanitizer的時(shí)候)。

when you build with the flag-fsanitize=address, if you are using C++ then it is worth setting-fno-omit-frame-pointertoo as you will get better results.

Address Sanitizer

TheAddress Sanitizer(asan for short) is very similar to Valgrind’s default “memcheck” tool. use-fsanitize=address to enable it.

Thread Sanitizer

TheThread Sanitizer(tsan for short) is designed to find race conditions in your code, very similar to the “Helgrind” tool in Valgrind. It has a typical slowdown of 5x – 15x and a memory overhead of 5x – 10x. Very much like the Address Sanitizer you compile it in using a simple flag,-fsanitize=thread. You should not try to use this with the asan flag. This won’t compile.

Undefined Behaviour Sanitizer

TheUndefined Behaviour Sanitizer(ubsan for short) does exactly what it says on the tin, it detects undefined behaviour usage in your application that can lead to bugs and portability issues and it is extremely fast. There are a whole bunch of different options to turn on here but the ones I typically use are-fsanitize=undefined -fsanitize=nullability.

不知道valgrind有沒有Undefined Behaviour Sanitizer 這個(gè)功能。經(jīng)過(guò)查證,valgrind好像還沒有類似工具。

參考網(wǎng)址:

https://github.com/google/sanitizers

https://clang.llvm.org/docs/AddressSanitizer.html

2valgrind

如果系統(tǒng)可以安裝 valgrind,則推薦使用valgrind,畢竟這個(gè)不影響代碼,而且可以調(diào)試 java 及 golang等很多程序,直接調(diào)試程序。

不過(guò),這兩個(gè)工具要在打印中顯示 問題行號(hào),則需要使用 -g -O0 來(lái)編譯。也可以加上 -g3。

Helgrind 相當(dāng)于 Thread Sanitizer。

不知道valgrind有沒有Undefined Behaviour Sanitizer 這個(gè)功能。經(jīng)過(guò)查證,valgrind好像還沒有類似工具。

靜態(tài)檢查工具:

static analyzers like clang-tidy, cppcheck, PVS


----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

微信公眾號(hào): 共鳴圈

歡迎討論,郵件: 924948$qq.com 請(qǐng)把$改成@

QQ群:263132197
QQ:924948

良辰美景補(bǔ)天漏,風(fēng)雨雷電洗地塵


----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

總結(jié)

以上是生活随笔為你收集整理的linux 下内存检查工具 valgrind 及 sanitizer 编译选项及静态检查工具的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。