Save breakpoints to file

左心房为你撑大大i 提交于 2019-12-01 03:08:13

问题


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.

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).


回答1:


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

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

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

Bonus:

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")

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

> bs 15

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.

Read more about aliases here.



来源:https://stackoverflow.com/questions/28841520/save-breakpoints-to-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!