美文网首页
调试python的段错误方法

调试python的段错误方法

作者: Magicknight | 来源:发表于2019-03-17 14:29 被阅读0次

  最近搞漏洞挖掘的时候,发现python会出现Segmentation fault,研究下发现是调用C++的程序引起的,想定位下问题。网上找了资料基本的方法有faulthandler调试、settrace调试、gdb调试。

1 使用faulthandler调试

在代码中加入

import faulthandler;faulthandler.enable()

命令行运行时使用:

python3 -Xfaulthandler  modelAttack.py

或者使用

PYTHONFAULTHANDLER=1 python3 test.py
faulthandler调试

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()
打印出错的python行

3 gdb调试

(1)启动gdb

gdb启动.png

(2)加载python3


加载python3.png

(3)运行调试程序
程序需要添加

import faulthandler;faulthandler.enable()
运行程序.png 运行程序.png

参考文章

  1. https://blog.richard.do/2018/03/18/how-to-debug-segmentation-fault-in-python/
  2. https://www.zhihu.com/question/268088832
    3.https://codeday.me/bug/20171023/89356.html

相关文章

网友评论

      本文标题:调试python的段错误方法

      本文链接:https://www.haomeiwen.com/subject/yvtumqtx.html