项目场景:
程序跑在离线的开发板上,新功能频繁导致导致崩溃,报错信息无法准确定位到实际出问题的位置,加太多打印也不现实,考虑使用 valgrind 进行调试。
软件安装
Valgrind
官方版本:Current Releases
OpenEuler 版本: src-openEuler/valgrind
安装流程参考以下命令
$ mkdir /tmp/valgrind
$ cp valgrind-3.22.0.tar.bz2 /tmp/valgrind/
$ cd /tmp/valgrind
$ bzip2 -d valgrind-3.22.0.tar.bz2
$ tar -xf valgrind-3.22.0.tar.bz2
$ cd valgrind-3.22.0
$ ./configure && make
$ sudo make install
安装完成尝试调试程序的时候我们很可能见到这样的错误提示
==21276== Memcheck, a memory error detector
==21276== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==21276== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
==21276== Command: ls
==21276==
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: strlen
valgrind: in an object with soname matching: ld-linux-x86-64.so.2
valgrind: was not found whilst processing
valgrind: symbols from the object with soname: ld-linux-x86-64.so.2
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 packa