蟒蛇跟踪分割故障 [英] python tracing a segmentation fault

查看:125
本文介绍了蟒蛇跟踪分割故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发的C扩展Python的广告我得到了一些设计缺陷(在开发过程中不可避免的...)。

I'm developing C extensions from python ad I obtain some segfaults (inevitable during the development...).

我在寻找一种方式来显示它在$ C $的C线的段错误发生(的想法就像是跟踪code的每一行),我该怎么做呢?

I'm searching a way to display at which line of code the segfault happens (an idea is like tracing every single line of code), how I can do that?

推荐答案

下面是一个方式来输出的Python的每一行的code运行的文件名和行号:

Here's a way to output the filename and line number of every line of Python your code runs:

import sys

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

def test():
    print "Line 8"
    print "Line 9"

sys.settrace(trace)
test()

输出:

call, test.py:7
line, test.py:8
Line 8
line, test.py:9
Line 9
return, test.py:9

(你可能想要写跟踪输出到文件中,当然)。

(You'd probably want to write the trace output to a file, of course.)

这篇关于蟒蛇跟踪分割故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆