Linux程式崩潰(segment fault)原因的調試

來源:互聯網
上載者:User
 主要有兩種方法:
一是用gdb,二是用valgrind

1.先用 ulimit -c unlimited 設定環境
2.重新運行程式,等待 segment fault,應該會產生 core 檔案
3.gdb <可執行程式> core*

以下是gdb ./UserStatsControl core.12345的輸出

#0 0x00000000 in ?? ()
(gdb) bt
#0 0x00000000 in ?? ()
#1 0x00ab9854 in SP_EventCallback::onWrite (fd=20, events=4, arg=0xb5100470) at

speventcb.cpp:190
#2 0x008bc540 in event_base_loop (base=0x90dd3f0, flags=Variable "flags" is not available.
) at event.c:315
#3 0x00abb3ed in SP_Server::start (this=0xbffd0de0) at spserver.cpp:236
#4 0x00abaf17 in SP_Server::eventLoop (arg=0xbffd0de0) at spserver.cpp:118
#5 0x00abaef1 in SP_Server::runForever (this=0xbffd0de0) at spserver.cpp:109
#6 0x0804bb9b in main (argc=1, argv=0xbffd0f84) at UserStatsControl.cpp:71

可知是speventcb.cpp:190 一行引起的問題。

還有一個專用工具valgrind ,專門用來檢查c++記憶體流失等問題,http://valgrind.org/

以下是valgrind --leak-check=yes ./UserStatsControl的輸出:

UserStatsControl[14440]: userCollectD connected(20.38): 192.168.14.11
==14440== Invalid read of size 4
==14440== at 0x402C470: SP_EventCallback::onRead(int, short, void*) (speventcb.cpp:106)
==14440== by 0x400D53F: event_base_loop (event.c:315)
==14440== by 0x402E3EC: SP_Server::start() (spserver.cpp:236)
==14440== by 0x402DF16: SP_Server::eventLoop(void*) (spserver.cpp:118)
==14440== by 0x402DEF0: SP_Server::runForever() (spserver.cpp:109)
==14440== by 0x804BB32: main (UserStatsControl.cpp:71)
==14440== Address 0x63373C8 is 0 bytes inside a block of size 8 free'd
==14440== at 0x400518E: operator delete(void*) (vg_replace_malloc.c:246)
==14440== by 0x4029AEE: SP_DefaultMsgDecoder::~SP_DefaultMsgDecoder()

(spmsgdecoder.cpp:29)
==14440== by 0x402ACFF: SP_Request::setMsgDecoder(SP_MsgDecoder*) (sprequest.cpp:31)
==14440== by 0x804C065: UserStatsHandler::start(SP_Request*, SP_Response*)

(UserStatsHandler.cpp:22)
==14440== by 0x402D5FE: SP_EventHelper::start(void*) (speventcb.cpp:472)
==14440== by 0x402AEF0: SP_SimpleTask::run() (spexecutor.cpp:56)
==14440== by 0x402B501: SP_Executor::worker(void*) (spexecutor.cpp:158)
==14440== by 0x40280DE: SP_ThreadPool::wrapperFunc(void*) (spthreadpool.cpp:154)
==14440== by 0x38E370: start_thread (in /lib/tls/libpthread-2.3.4.so)
==14440== by 0x2F8FFD: clone (in /lib/tls/libc-2.3.4.so)
pure virtual method called
terminate called without an active exception

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.