valgrind-內存泄漏定位工具

1、前言

  • valgirnd 是一套開放源代碼的動態調試工具集合。能夠檢測內存管理錯誤,線程BUG等。valgirnd是由內核以及基于內核的其他調試工具組成。內核類似于一個框架,它模擬了一個cpu的環境,并提供服務給其他工具使用。而其他工具則類似于插件,利用內核提供的服務完成各種特定的內存調試任務。

2、介紹

valgirnd是以下工具的集合:

  • 1、memcheck:這是valgrind應用最廣泛的工具,一個重量級的內存檢車器,能夠發現開發中絕大多數內存錯誤使用的情況。比如:使用未初始化的內存,使用已經釋放了的內存,內存訪問越界等。
  • 2、callgrind:主要用來檢查程序中函數調用過程中出現的問題。
  • 3、cachegrind:主要用來檢查程序中緩存使用出現的問題。
  • 4、helgrind:主要用來檢查多線程中出現的競爭的問題。
  • 5、massif:主要用來檢車程序中堆棧使用過程出現的問題。
  • 6、externsion:可以利用core提供的功能,自己編寫特定的內存調試工具。

3、編譯

  • 源碼下載:valgirnd官網下載連接
  • 解壓后進行valrind目錄下面,執行./autogen.sh
  • 創建builsh.sh腳本:
./configure \
prefix=$(pwd)/output \
--host=armv7-linux \
CFLAGS="-fPIC -mfloat-abi=hard -mfpu=vfp" \
CC=/home/leo/sv82x/toolchain/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc \
CXX=/home/leo/sv82x/toolchain/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ \
  • 編譯和安裝:make;make install

4、 運行

  • 在板載的終端輸入測試命令,查看valgirnd是否能正常運行,如果出現一堆解釋性文字,則表示成功:./valgrind --help
  • 通過以下命令進行執行的內存泄漏檢測:
    ./valgrind --error-limit-no --leak-check=full --tool=memcheck ./test.bin

5、遇到的問題分析

5.1 、 交叉編譯期間的問題

  • 在配置 configure 時遇到類似以下問題,解決方案請參考buil.sh腳本中的–host參數設置
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-ca9-linux-gnueabihf-strip... no
checking for strip... strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking whether ln -s works... yes
checking for arm-ca9-linux-gnueabihf-gcc... /opt/arm-ca9-linux-gnueabihf-6.5/bin/arm-ca9-linux-gnueabihf-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether /opt/arm-ca9-linux-gnueabihf-6.5/bin/arm-ca9-linux-gnueabihf-gcc accepts -g... yes
checking for /opt/arm-ca9-linux-gnueabihf-6.5/bin/arm-ca9-linux-gnueabihf-gcc option to accept ISO C89... none needed
checking whether /opt/arm-ca9-linux-gnueabihf-6.5/bin/arm-ca9-linux-gnueabihf-gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of /opt/arm-ca9-linux-gnueabihf-6.5/bin/arm-ca9-linux-gnueabihf-gcc... gcc3
checking how to run the C preprocessor... /opt/arm-ca9-linux-gnueabihf-6.5/bin/arm-ca9-linux-gnueabihf-cpp
checking whether we are using the GNU C++ compiler... yes
checking whether /opt/arm-ca9-linux-gnueabihf-6.5/bin/arm-ca9-linux-gnueabihf-g++ accepts -g... yes
checking dependency style of /opt/arm-ca9-linux-gnueabihf-6.5/bin/arm-ca9-linux-gnueabihf-g++... gcc3
checking for arm-ca9-linux-gnueabihf-ranlib... no
checking for ranlib... ranlib
configure: WARNING: using cross tools not prefixed with host triplet
checking for a sed that does not truncate output... /bin/sed
checking for ar... /usr/bin/ar
checking for perl... /usr/bin/perl
checking for gdb... /usr/bin/gdb
checking dependency style of /opt/arm-ca9-linux-gnueabihf-6.5/bin/arm-ca9-linux-gnueabihf-gcc... gcc3
checking for diff -u... yes
checking for a supported version of gcc... ok (6.5.0)
checking build system type... x86_64-unknown-linux-gnu
checking host system type... arm-ca9-linux-gnueabihf
checking for a supported CPU... no (arm)
configure: error: Unsupported host architecture. Sorry
  • 配置configure 時遇到類似以下問題,原因是交叉工具鏈沒有找到,請排查工具鏈的路徑
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-ca9-linux-gnueabihf-strip... no
checking for strip... strip
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking whether ln -s works... yes
checking for arm-ca9-linux-gnueabihf-gcc... arm-ca9-linux-gnueabihf-gcc
checking whether the C compiler works... no
configure: error: in `/home/const/workspace/Download/valgrind-3.12.0':
configure: error: C compiler cannot create executables
See `config.log' for more details

5.2、使用期間的問題

  • 測試valgrind或者使用時,出現以下問題,其原因是沒有找到valgrind的lib庫文件,同時使用LD_LIBRARY_PATH環境變量也是沒有用的。
valgrind: failed to start tool 'memcheck' for platform 'arm-linux': No such file or directory

解決辦法:在板載終端上設置valgrind的環境變量:

export VALGRIND_LIB=/tmp/nfs/valgrind/lib/libexec/valgrind
#這個根據交叉編譯后安裝的實際路徑填寫
  • 使用時出現 ld-linux-armhf.so.3的錯誤,原因是板載的 ld-2.29.so是被stripped后的動態庫文件,而valgrind需要的卻是debug版本的動態庫,需要注意的是ld-linux-armhf.so.3ld-2.29.so 的軟鏈接。
# /mnt/valgrind/bin/valgrind --error-limit=no --leak-check=full --tool=memcheck /usr/local/bin/sample
==701== Memcheck, a memory error detector
==701== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==701== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info
==701== Command: /usr/local/bin/sample
==701== valgrind:  Fatal error at startup: a function redirection
valgrind:  which is mandatory for this platform-tool combination
valgrind:  cannot be set up.  Details of the redirection are:
valgrind:  
valgrind:  A must-be-redirected function
valgrind:  whose name matches the pattern:      strcmp
valgrind:  in an object with soname matching:   ld-linux-armhf.so.3
valgrind:  was not found whilst processing
valgrind:  symbols from the object with soname: ld-linux-armhf.so.3
valgrind:  
valgrind:  Possible fixes: (1, short term): install glibc's debuginfo
valgrind:  package on this machine.  (2, longer term): ask the packagers
valgrind:  for your Linux distribution to please in future ship a non-
valgrind:  stripped ld.so (or whatever the dynamic linker .so is called)
valgrind:  that exports the above-named function using the standard
valgrind:  calling conventions for this platform.  The package you need
valgrind:  to install for fix (1) is called
valgrind:  
valgrind:    On Debian, Ubuntu:                 libc6-dbg
valgrind:    On SuSE, openSuSE, Fedora, RHEL:   glibc-debuginfo
valgrind:  
valgrind:  Note that if you are debugging a 32 bit process on a
valgrind:  64 bit system, you will need a corresponding 32 bit debuginfo
valgrind:  package (e.g. libc6-dbg:i386).
valgrind:  
valgrind:  Cannot continue -- exiting now.  Sorry.

網上很多說用not stripped的ld-2.29.so去替換目標板上的ld-2.29.so,解決辦法相對來說非常的繁瑣而且廢時間,一般嵌入式linux系統,文件系統這塊基本都是只讀文件系統,而且只是用于調試,沒必要將文件系統重新燒來燒去,并且還需要重新交叉編譯ld庫。所以需要解決就是在調用ld-2.29.so的時候,需要使用not stripped的動態庫,而不是stripped的庫。經過一番搜索資料后通過以下的命令可以正確調用not stripped的動態庫。

/tmp/nfs/sv82x/apps/sat_eeasytech/valgrind --tool=memcheck  --leak-check=full --main-stacksize=16777216 /tmp/nfs/sv82x/toolchain/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/lib/ld-linux-armhf.so.3 /tmp/nfs/sv82x/apps/sat_eeasytech/EEASYTECH_SAT.BIN

在使用過程中,按照實際的路徑配置即可。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/23170.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/23170.shtml
英文地址,請注明出處:http://en.pswp.cn/web/23170.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

紅酒:紅酒保存中的光照與避免陽光直射

在紅酒保存中,光照是一個常常被忽視的因素。光照對紅酒的影響是不可小覷的,因為陽光中的紫外線會加速紅酒的氧化,導致其口感和品質的下降。因此,在保存云倉酒莊雷盛紅酒時,應特別注意避免陽光直射。 陽光直射對紅酒的影…

企業代碼簽名證書1300元

隨著手機和電腦等設備的普及,越來越多的開發者進入軟件行業,為了軟件的安全性、完整性和可信度,開發者往往會使用由正規CA認證機構頒發的代碼簽名證書對軟件代碼進行數字簽名,來標識軟件的來源和軟件開發者的真實身份。今天就隨SS…

AGI時代下,計算機專業出身的程序員該何去何從?

Easy:單獨開個貼說一下吧。 如果你計算機、軟件工程、通信、電子、網絡等相關專業本科畢業,也考慮前后端/測試崗,戳 技術大廠,6險1金,待遇不錯。 提前說明,一切以古代思維對AGI時代的推演,都是可…

博物館文物庫房管理軟件

博物館作為文化遺產的守護者和傳承者,承載著人類智慧與文明的結晶。在博物館的背后,一個龐大而嚴密的管理系統支撐著文物的保護與展示。而其中,文物庫房管理軟件的使用,無疑是一項重要的管理工具。 文物庫房管理軟件的功能具有多樣…

【CentOS 7】挑戰探索:在CentOS 7上實現Python 3.9的完美部署指南

【CentOS 7】挑戰探索:在CentOS 7上實現Python 3.9的完美部署指南 大家好 我是寸鐵👊 總結了一篇【CentOS 7】挑戰探索:在CentOS 7上實現Python 3.9的完美部署指南詳細步驟? 喜歡的小伙伴可以點點關注 💝 前言 此篇教程只適用于p…

【java前端課堂】05_類的多態

類的多態是面向對象編程的三大特性之一,與封裝和繼承并列。多態性允許我們將父對象設置為與其子對象相等的技術,讓我們可以把一個子對象當作父對象對待。在Java中,多態主要體現在以下三個方面: 方法的重載(Overloadin…

【Mybatis】源碼分析-高級應用

1、Mybatis配置文件深入理解 1.2、動態SQL語句 Mybatis 的映射?件中,前?我們的 SQL 都是?較簡單的,有些時候業務邏輯復雜時,我們的 SQL是動態變化的,此時在前?的學習中我們的 SQL 就不能滿?要求了。 1.2.1、條件判斷 我們根…

技巧:合并ZIP分卷壓縮包

如果ZIP壓縮文件文件體積過大,大家可能會選擇“分卷壓縮”來壓縮ZIP文件,那么,如何合并zip分卷壓縮包呢?今天我們分享兩個ZIP分卷壓縮包合并的方法給大家。 方法一: 我們可以將分卷壓縮包,通過解壓的方式…

E10:系統彈窗提示

效果– window.WeFormSDK.showMessage("這是一個E10的提示", 3, 2); const onClickCreate () > console.log("create"); const onClickSave () > console.log("save"); const onClickCancel () > dialogComponent?.destroy(); co…

Java四舍五入保留小數

這里介紹兩種方法: package Book.jj.hh;import java.text.DecimalFormat; //使用DecimalFormat類 public class Demo1 {public static void main(String[] args) {double num 123.52631;DecimalFormat a new DecimalFormat("#.00"); //小數點后有幾個0…

SpringCloud Gateway基礎入門與使用實踐總結

官網文檔:點擊查看官網文檔 Cloud全家桶中有個很重要的組件就是網關,在1.x版本中都是采用的Zuul網關。但在2.x版本中,zuul的升級一直跳票,SpringCloud最后自己研發了一個網關替代Zuul,那就是SpringCloud Gateway一句話…

抖音賬號永久封號后強制注銷釋放實名!一分鐘教程方法公開

目前方法是可行的,不知道能保持多久! 下載舊版本抖音:下載抖音6.8版本或5.8版本的老版本應用。 使用封禁手機號登錄:使用已被永久封禁的手機號登錄舊版本的抖音應用。 賬號注銷操作: 在設置中找到賬號與安全的選項。…

從零開始發布你的第一個npm插件包并在多項目中使用

引言 在開源的世界里,每個人都有機會成為貢獻者,甚至是創新的引領者。您是否有過這樣的想法:開發一個解決特定問題的小工具,讓她成為其他開發者手中的利器?今天,我們就來一場實戰訓練,學習如何將…

【ubuntu】增加samba服務和文件夾

發現ai -server的ubuntu機器無法git clone 下來github的文件所以 使用samba 連接到linux的文件夾proj然后在我的windows上git clone 即可。安裝samba Creating config file /etc/samba/smb.conf with new version Setting up libcephfs2 (17.2.7-0ubuntu0.22.04.1) ... Setting…

漏洞挖掘 | 驗證碼繞過

還是老規矩,開局一個登錄框,中途漏洞全靠舔,先來研究一下這個登錄窗口 很好,發現有驗證碼登錄,先測試測試能不能并發 看來沒有,只成功發送了兩條,再看看驗證碼是不是4位 很好,是4位。…

UE5-AI

AI角色 角色控制器 AI角色必須要一個角色控制器 角色控制器最基本只需要執行行為樹,在EventOnPossess后runBehaviorTree 如果要的是一個角色,可以創建一個Character,在類默認設置中可以找到 Pawn->AIControllerClass,在這里…

Android 架構組件面試問答

1. 什么是 Android Architecture Components? 答: 組件是一組庫,可幫助您設計健壯、可測試且可維護的應用程序。它們提供了一種清晰且慣用的方式來使用 REST API。這些組件包括 Room、ViewModel、LiveData 等。 2. 什么是LiveData&#xff…

Java接口的變更過程

Java 接口相信所有學過 Java 的人一定都知道,而且 99% 的人一定都背過這個面試題:Java 接口和抽象類的區別是什么?答案都是什么接口方法不能有實現,都是抽象的,接口的方法都默認為 public 修飾等等之類的,這…

推箱子小游戲C++

推箱子是一款經典的益智游戲,玩家需要通過推動箱子來達到特定的目標。在C中實現這樣的小游戲需要考慮游戲邏輯、用戶輸入、圖形界面(如果需要的話)以及可能的關卡設計。 下面是一個簡單的推箱子游戲的實現框架: 定義游戲環境 創建…

DSP問題:CCS更改工程名導入報錯

1、問題現象 復制一個工程出來后,修改版本號,重新導入工程后報錯。 顯示項目描述無效。 2、問題原因 由于CCS無法通過工程描述中找到指定名字文件夾。使用記事本打開.project文件,里面的描述還是以前的文件夾名,所以導入時報…