Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python possible to debug without modifying code

It seems that debugging python code is a trivial task, just insert the following lines to trigger the debugger.

import pdb
pdb.set_trace()

Yeah, so I tried that, and it works really well. It's a decent debugger.

But is it possible to launch an unmodified python program, perhaps specifying a text file, listing breakpoint locations? That's how I usually do it in Java or Flash.

like image 212
Bryan Hunt Avatar asked Dec 09 '22 02:12

Bryan Hunt


2 Answers

Save a file called .pdbrc in the same folder as your script file. Put in it your breakpoint information:

b 3
b 5
b 70
b 89

Run your script in pdb like so:

python -m pdb myscript.py

and pdb will pick up and insert your breakpoints. Unfortunetly it won't save any changes you make to them while debugging.

Alternatively you can specify them on the first line

(Pdb) b 3;;b 5;;b 70;;b 89
like image 130
fraxel Avatar answered Dec 20 '22 16:12

fraxel


As explained in the documentation, you can run it with:

python -m pdb myscript.py
like image 37
Wooble Avatar answered Dec 20 '22 18:12

Wooble