接前文:
[daily] 內存越界的分析與定位
如前文提及, 使用sanitizer-address 可以有效的檢查程序的內存問題。
當時在CentOS7中,雖然也可以使用,但是卻遇到如下兩個問題:
1. 程序崩潰時的打印信息中,缺少代碼信息,雖然知道出了問題,但是卻並不知道具體問題處在哪一個地方,哪一行。
2. 不能對 sanitizer-address 設置斷點。從而在發生問題的時候,保留運行信息。
對比,我的archlinux,卻沒有這個問題。我想唯一的區別應該就是gcc的版本問題。
arch的gcc版本是7, CentOS7的gcc版本是4.8.5
所以解決這問題的思路就是安裝一個高版本的gcc。
那么在 CentOS7中,安裝高版本gcc,一般有兩個方法:
1, 使用源碼。
2. 使用SCLo
什么是SCLo,簡單的說,就是比epel更豐富的軟件包集合:
https://www.softwarecollections.org/en/about/
快速使用方法:
https://www.softwarecollections.org/en/docs/
yum install centos-release-scl
好了,有了SCLo庫之后,我們就可以安裝GCC7了。
yum install devtoolset-7-gcc
再裝GCC7的 libasan
yum install devtoolset-7-libasan-devel
他們是devtoolset,和常規的軟件還不太一樣
devtoolset-7 - Developer Toolset is designed for developers working on CentOS or Red Hat Enterprise Linux platform. It provides current versions of the GNU Compiler Collection,
GNU Debugger, and other development, debugging, and performance monitoring tools.
因為他們都是裝在opt下面的,
[root@dpdk chimpanzee]# rpm -ql devtoolset-7-libasan-devel /opt/rh/devtoolset-7/root/usr/lib/gcc /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7 /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/libasan.a /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/libasan.so /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/libasan_preinit.o /opt/rh/devtoolset-7/root/usr/share/doc/devtoolset-7-libasan-devel-7.2.1 /opt/rh/devtoolset-7/root/usr/share/doc/devtoolset-7-libasan-devel-7.2.1/ChangeLog.bz2 /opt/rh/devtoolset-7/root/usr/share/doc/devtoolset-7-libasan-devel-7.2.1/LICENSE.TXT [root@dpdk chimpanzee]#
配置一下,就可以用了
[root@dpdk chimpanzee]# source /opt/rh/devtoolset-7/enable [root@dpdk chimpanzee]# gcc -v ... ... gcc version 7.2.1 20170829 (Red Hat 7.2.1-1) (GCC)
這個 enable 屬於軟件 devtoolset-7-runtime
[root@dpdk chimpanzee]# rpm -qf /opt/rh/devtoolset-7/enable devtoolset-7-runtime-7.0-8.el7.sc1.x86_64
這個時候,再去使用sanitizer編譯程序,之后就能夠看見調試信息了,也能夠成功的斷到libasan的斷點了。
