原文地址:https://blog.csdn.net/qq_38631503/article/details/80093855
万恶的Segmentation fault(core dumped)
生成core文件
$
ulimit -c unlimited
$
ls
clion CMakeCache.txt CMakeFiles cmake_install.cmake core Makefile
使用gdb调试core文件
$ gdb clion core
错误片段
...
[New LWP 12543
]
[New LWP 12546
]
[Thread debugging using libthread_db enabled
]
Using host libthread_db library
"/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `./clion'.
Program terminated with signal SIGSEGV, Segmentation fault.
[Current thread is 1
(Thread 0x7fb2d8d1df40
(LWP 12543
))]
在gdb中使用where查看更详细信息
(gdb) where
# 错误在main.cpp:72
Undefined command: "". Try "help".
(gdb) #0 0x0000000000000000 in ?? ()
(gdb) #1 0x0000000000401722 in main () at /home/deepin/C/clion/main.cpp:72
错误代码
使用了已经delete的内存topi_conf
RdKafka
::Conf
*topi_conf
= RdKafka
::Conf
::create(RdKafka
::Conf
::CONF_TOPIC
);
if (!topi_conf
) {
fprintf(stderr, "Create Topic configuer failed: %s\n", errstr
.c_str());
exit(1);
}
delete topi_conf
;
if (topi_conf
->set("auto.offset.reset", "largest", errstr
) != RdKafka
::Conf
::CONF_OK
) {
fprintf(stderr, "Failed to set auto.offset.resetL %s\n", errstr
.c_str());
exit(1);
}