首页 > 文章列表 > python中pdb模块的运行原理

python中pdb模块的运行原理

Python pdb
417 2022-08-07

1、pdb模块不是c实现的内置模块,而是纯Python实现和包装的模块。

pdb.py是核心文件,它继承了bdb和cmd模块。

2、利用cmd模块定义和实现一系列调试命令的交互输入,基于sys.settrace插桩跟踪代码运行的栈帧。

根据不同的调试命令控制代码的运行和断点状态,并向控制台输出相应的信息。

实例

import pdb
def combine(s1,s2):      # define subroutine combine, which...
    s3 = s1 + s2 + s1    # sandwiches s2 between copies of s1, ...
    s3 = '"' + s3 +'"'   # encloses it in double quotes,...
    return s3            # and returns it.
a = "aaa"
pdb.set_trace()
b = "bbb"
c = "ccc"
final = combine(a,b)
print final

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。