将断点保存到文件 [英] Save breakpoints to file

查看:149
本文介绍了将断点保存到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在调试Python代码时,我从命令行通过ipdb运行脚本,并设置了多个断点.然后,我在一个或多个模块中进行一些更改,然后重新运行.但是,如果我只是使用运行模块不要重新加载.为了确保它们确实存在,我可以存在并完全重新启动Python,但是然后我需要重置所有断点,如果我有很多断点,又要一遍又一遍地做,这将很麻烦.

When debugging my Python code, I run a script through ipdb from the commandline, and set a number of breakpoints. Then I make some changes in one or more modules, and rerun. However, if I simply use run modules do not get reloaded. To make sure they do, I can exist and restart Python completely, but then I need to reset all breakpoints, which is tedious if I have many and if done over and over again.

有没有一种方法可以将断点保存到(i)pdb中的文件中,以便在不更改行号的小改动之后,我可以转储断点,重新启动Python + pdb,然后重新加载断点?等同于Matlabs X = dbstatus,保存/加载X和设置dbstop(X).

Is there a way to save breakpoint to a file in (i)pdb, so that after small changes that do not change line numbers, I can dump my breakpoints, restart Python + pdb, and reload my breakpoints? The equivalent to Matlabs X = dbstatus, saving/loading X, and setting dbstop(X).

推荐答案

您可以在工作路径中将断点保存到.pdbrc文件中,也可以将其全局保存到您的主目录中.文件应具有以下内容:

You can save the breakpoints to .pdbrc file in a working path or globally to your home dir. File should have something like this:

# breakpoint 1
break /path/to/file:lineno

# breakpoint 2
break /path/to/file:lineno

您可以以各种方式定义断点,就像在交互模式下一样.因此,只有break 4break method也会起作用.

You can define breakpoints various ways, just like in the interactive mode. So just break 4 or break method will work too.

此文件对pdb和ipdb均适用,因为以后将具有pdb的所有功能以及更多功能.

This file works for both, pdb and ipdb, since later has everything pdb has and more.

奖金:

您可以使用alias来更轻松地保存断点. 例如:

You could use alias to more easily save breakpoints. For example:

# append breakpoint to .pdbrc in current working directory
# usage: bs lineno
alias bs with open(".pdbrc", "a") as pdbrc: pdbrc.write("break " + __file__ + ":%1\n")

将上面的内容放入您的全局.pdbrc并像这样使用它:

Put above to your global .pdbrc and use it like this:

> bs 15

这会将断点语句附加到当前文件第15行的本地.pdbrc文件中.

This will append a breakpoint statement to a local .pdbrc file for a line 15 of current file.

这不是完美的解决方案,但对我来说足够接近.根据需要调整命令.

It is not perfect solution, but close enough for me. Tune the command to your needs.

在此处详细了解别名.

这篇关于将断点保存到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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