Reputation: 1241
I use ipython and run -d foo.py
to debug my program. But every time I re-debug the program, I have to reset all the breakpoints. This is annoying when you have multiple breakpoints or multiple py
files.
Is it possible to let ipython or pdb to remember the breakpoints and reused them in next debug session.
Upvotes: 1
Views: 334
Reputation: 40683
You can write an initialisation file for pdb which lists all the break points you want to add to the program. It must be called .pdbrc
and placed either in the working directory or your home directory. Break points can be specified by either line number or by function name.
eg.
a.py
import b
def doX():
print("in x") # line 4
b.doY()
if __name__ == "__main__":
doX()
b.py
def doY():
print("in y") # line 2
.pdbrc
# the following are all equivalent -- placing a breakpoint on entry into doX
break 4
break a.py:4
break doX
break a.doX
# placing a breakpoint on entry into doY
break b.py:2
break b.doY
Output
In [8]: %run -d a.py
Breakpoint 1 at /home/user/Desktop/python-stuff/a.py:1
NOTE: Enter 'c' at the ipdb> prompt to continue execution.
Breakpoint 2 at /home/user/Desktop/python-stuff/a.py:3
Breakpoint 3 at /home/user/Desktop/python-stuff/b.py:1
> /home/user/Desktop/python-stuff/a.py(1)<module>()
1---> 1 import b
2
2 3 def doX():
ipdb> c
> /home/user/Desktop/python-stuff/a.py(4)doX()
2 3 def doX():
----> 4 print("in x")
5 b.doY()
ipdb> c
in x
> /home/user/Desktop/python-stuff/b.py(2)doY()
3 1 def doY():
----> 2 print("in y")
3
ipdb> c
in y
Upvotes: 4