最近搞漏洞挖掘的时候,发现python会出现Segmentation fault,研究下发现是调用C++的程序引起的,想定位下问题。网上找了资料基本的方法有faulthandler调试、settrace调试、gdb调试。
1 使用faulthandler调试
在代码中加入
import faulthandler;faulthandler.enable()
命令行运行时使用:
python3 -Xfaulthandler modelAttack.py
或者使用
PYTHONFAULTHANDLER=1 python3 test.py

2 使用settrace打印出错的python行
在代码中加入如下的代码:
def trace(frame, event, arg):
print ("%s, %s:%d" % (event, frame.f_code.co_filename, frame.f_lineno))
return trace
sys.settrace(trace)
testfunction()

3 gdb调试
(1)启动gdb

(2)加载python3

(3)运行调试程序
程序需要添加
import faulthandler;faulthandler.enable()


网友评论