標籤:linux 雲端服務器 valgrind 記憶體泄露 記憶體越界
最近伺服器程式出了一個崩潰,確定是記憶體位址訪問越界,但是不能定位在哪裡,沒辦法只好用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
linux安裝valgrind