1. 首先设置系统允许生成core dump文件
步骤一:开启core dump文件生成
ulimit -c unlimited
步骤二:设置core dump文件位置
vi /etc/sysctl.conf
修改(添加)如下两个变量
kernel.core_pattern =/var/core/core_%e_%p
kernel.core_uses_pid= 0
这里是改为生成目录在/var/core/,%e代表程序名称,%p是进程ID
如果想直接生成在可执行文件相同目录,前面不要加任何目录,直接
kernel.core_pattern =core_%e_%p
步骤三:让修改生效
sysctl -p/etc/sysctl.conf
2. 准备工作
准备工作
安装 gdb 和 python2.7-dbg:
sudo apt-get install gdb python2.7-dbg
设置 /proc/sys/kernel/yama/ptrace_scope:
echo 0 |sudo tee /proc/sys/kernel/yama/ptrace_scope
3. gdb调试Python core文件的方法
使用gdb打开并调试core文件
gdb python core
$ gdb python core
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from python...Reading symbols from /usr/lib/debug/.build-id/04/9b3068eb18127661de41257e012a54934fb0ee.debug...done.
done.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `python2 mantra_hmi_pro.py'.
Program terminated with signal SIGABRT, Aborted.
#0 0x00007f04fdf36428 in __GI_raise (sig=