最近服务器程序出了一个崩溃,确定是内存地址访问越界,但是不能定位在哪里,没办法只好用valgrind来跑一下,以前公司的服务器是上都默认安装了,突然发现云服务器上没有安装这个软件,所以记录一下如何安装。
1、下载最新版本的valgrind:
http://www.valgrind.org/downloads/valgrind-3.9.0.tar.bz2
解压安装包:tar –jxvf valgrind-3.9.0.tar.bz2,解压后生成目录valgrind-3.9.0。
目前支持的平台,在官网上列表如下:
{x86,amd64,arm,ppc32,ppc64,s390x,mips32,mips64}-linux, arm-android (2.3 and later), x86-android (4.0 and later) and {x86,amd64}-darwin (Mac OS X 10.7, with limited support for 10。
2、安装前配置编译选项,所以配置如下:
# cd valgrind-3.9.0
# ./autogen.sh
# ./configure --prefix=/home/valgrind/bin
3、编译和安装valgrind
# make
# make install
4、到这来已经安装成功了,但还不能直接使用,需要创建一个软连接。
# cd /usr/bin/
# ln -s /home/valgrind/bin/bin/valgrind valgrind
最后我们测试一下吧,如果运行so文件失败,可能需要设置库目录。
# export LD_LIBRARY_PATH=`pwd`
# valgrind ./WorldFrame_d -c 2
然后看看终端的显示,确定是否正确安装。
==30079== Memcheck, a memory error detector ==30079== Copyright (C) 2002-2013, and GNU GPL‘d, by Julian Seward et al. ==30079== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info ==30079== Command: ./WorldFrame_d -c 2 ==30079== begin load xml... begin read file... fileLength = 846 begin decrypt file... pTiXmlDocument::begin parse file... ==30079== Conditional jump or move depends on uninitialised value(s) ==30079== at 0x50F351F: TiXmlBase::StringEqual(char const*, char const*, bool, TiXmlEncoding) (tinyxmlparser.cpp:549) ==30079== by 0x50F426F: TiXmlElement::Parse(char const*, TiXmlParsingData*, TiXmlEncoding) (tinyxmlparser.cpp:1094) ==30079== by 0x50F399D: TiXmlDocument::Parse(char const*, TiXmlParsingData*, TiXmlEncoding) (tinyxmlparser.cpp:744) ==30079== by 0x50E8049: CSchemeEngine::__LoadXML(char const*, bool, TiXmlDocument*) (SchemeEngine.cpp:353) ==30079== by 0x50E7E29: CSchemeEngine::__Load(char const*, CCsvReader*, TiXmlDocument*, bool&) (SchemeEngine.cpp:277) ==30079== by 0x50E76B1: CSchemeEngine::LoadScheme(char const*, ISchemeUpdateSink*) (SchemeEngine.cpp:92) ==30079== by 0x4391D0: ServerScheme::LoadScheme(ISchemeEngine*, char const*, unsigned int) (ServerScheme.cpp:11) ==30079== by 0x433E0A: main (ServerApp.cpp:62) ==30079== ==30079== Conditional jump or move depends on uninitialised value(s) ==30079== at 0x50F2D35: TiXmlBase::SkipWhiteSpace(char const*, TiXmlEncoding) (tinyxmlparser.cpp:315) ==30079== by 0x50F3ABB: TiXmlDocument::Parse(char const*, TiXmlParsingData*, TiXmlEncoding) (tinyxmlparser.cpp:770) ==30079== by 0x50E8049: CSchemeEngine::__LoadXML(char const*, bool, TiXmlDocument*) (SchemeEngine.cpp:353) ==30079== by 0x50E7E29: CSchemeEngine::__Load(char const*, CCsvReader*, TiXmlDocument*, bool&) (SchemeEngine.cpp:277) ==30079== by 0x50E76B1: CSchemeEngine::LoadScheme(char const*, ISchemeUpdateSink*) (SchemeEngine.cpp:92) ==30079== by 0x4391D0: ServerScheme::LoadScheme(ISchemeEngine*, char const*, unsigned int) (ServerScheme.cpp:11) ==30079== by 0x433E0A: main (ServerApp.cpp:62) ==30079== Sock.dll, version 30 --LongWorkerProc(), long worker thread startup, id=30080