[daily] 在CentOS7中使用 sanitizer-address 发现内存问题 / CentOS7使用SCLo软件源安装devtoolset软件

接前文:

[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的断点了。

原文地址:https://www.cnblogs.com/hugetong/p/8303160.html