python segmentation fault

1:使用faulthandler 调试
在代码中加入
import faulthandler;faulthander.enable()

然后通过python3 -Xfaulthander xx.py 执行.

打印挂掉是的堆栈
Thread 0x0000ffffbb0d8b20 (most recent call first):
File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1443 in _call_tf_sessionrun
File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1350 in _run_fn
File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1365 in _do_call
File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1359 in _do_run
File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1180 in _run
File "/usr/local/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 956 in run

2:通过frame.f_code.co_filename,frame.f_lineno 来显示调用文件的name和行号,通过event显示事件,这里的事件就是call 调用
def trace(frame,event,arg):
    print("%s, %s:%d" % (event,frame.f_code.co_filename,frame.f_lineno))
    return trace
sys.settrace(trace)


import sys
def trace(frame,event,arg):
    print("%s, %s:%d" % (event,frame.f_code.co_filename,frame.f_lineno))
    return trace
sys.settrace(trace)
print("hello")


[root@localhost rpm]# python2 hello.py
hello
call, /usr/lib64/python2.7/_weakrefset.py:38
call, /usr/lib64/python2.7/_weakrefset.py:38


3:通过gdb 中执行
[root@localhost rpm]# gdb
GNU gdb (GDB) Red Hat Enterprise Linux 8.2-6.el8
Copyright (C) 2018 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 "aarch64-redhat-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".
(gdb) file python2
Reading symbols from python2...Reading symbols from .gnu_debugdata for /usr/bin/python2.7...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Missing separate debuginfos, use: yum debuginfo-install python2-2.7.16-12.module_el8.1.0+219+cf9e6ac9.aarch64
(gdb) run hello.py
Starting program: /usr/bin/python2 hello.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
hello
call, /usr/lib64/python2.7/_weakrefset.py:38
call, /usr/lib64/python2.7/_weakrefset.py:38
[Inferior 1 (process 45468) exited normally]
发布了1437 篇原创文章 · 获赞 64 · 访问量 132万+

猜你喜欢

转载自blog.csdn.net/tiantao2012/article/details/105138040