There are two main methods:
One is to use GDB, and the other is to use valgrind.
1. Set the environment with ulimit-C Unlimited
2. Run againProgram, Wait for segment fault, and the core file should be generated
3. GDB <executable program> core *
The output of GDB./userstatscontrol core.12345 is as follows:
#0 0x00000000 in ?? ()
(GDB) BT
#0 0x00000000 in ?? ()
#1 0x00ab9854 in sp_eventcallback: onwrite (FD = 20, events = 4, Arg = 0xb5100470)
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
It can be seen that speventcb. cpp: 190 is a problem caused by a row.
There is also a dedicated tool valgrind, specifically used to check problems such as C ++ Memory leakage, http://valgrind.org/
The output of valgrind -- leak-check = yes./userstatscontrol is as follows:
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