Linux程序崩溃(segment fault)原因的调试
来源:互联网 发布:人工智能世界排名 编辑:程序博客网 时间:2024/05/18 00:23
主要有两种方法:
一是用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
一是用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
- Linux程序崩溃(segment fault)原因的调试
- Linux程序崩溃(segment fault)原因的调试
- Linux程序崩溃(segment fault)原因的调试
- Linux程序崩溃(segment fault)原因的调试 gdb, valgrind
- 利用backtrace诊断 Segment Fault 崩溃原因
- 产生segment fault的原因及调试方法总结
- 造成segment fault的原因
- segment fault 的调试方法
- 段错误(segment fault)的几种原因
- 最常见的Linux用户程序异常----Segment Fault
- Linux 段错误调试Segment Fault
- 调试segment fault
- Linux下c/c++开发之程序崩溃(Segment fault)时内核转储文件(core dump)生成设置方法
- Linux下的段错误(Segmentation fault)产生的原因及调试方法(经典)
- Linux下的段错误(Segmentation fault)产生的原因及调试方法(经典)
- Linux下的段错误(Segmentation fault)产生的原因及调试方法(经典)
- Linux下的段错误(segmentation fault)产生的原因及调试方法
- Linux下的段错误(segmentation fault)产生的原因及调试方法
- 关于cryptography得一点新的
- asio学习2: TCP服务器端:对准时间 解析
- Oracle开发专题之:时间运算
- 现的从1到N的出现M的次数算法
- Oracle开发专题之:时间运算2(日期截取及四舍五入)
- Linux程序崩溃(segment fault)原因的调试
- Oracle开发专题之:分析函数(OVER)
- 100个不能错过的网站
- Oracle开发专题之:分析函数2(Rank, Dense_rank, row_number)
- CSDN的博客做得真垃圾,垃圾!
- 如何禁止用户选取页面中的文字
- asio学习3: 异步tcp服务器端(datetime)
- Linux循环缓冲实现
- GetPrivateProfileString 和GetPrivateProfileInt