Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDB how to break on exit?

Tags:

python

pdb

How can I get the python debugger, pdb to break on exit? Also, why I am at it, How can I break on exceptions raised?

like image 297
h4ck3rm1k3 Avatar asked Aug 18 '12 15:08

h4ck3rm1k3


People also ask

How do I break out of pdb?

To start execution, you use the continue or c command. If the program executes successfully, you will be taken back to the (Pdb) prompt where you can restart the execution again. At this point, you can use quit / q or Ctrl+D to exit the debugger.

How do you break a loop in pdb?

Once you get you pdb prompt . Just hit n (next) 10 times to exit the loop.

How do you exit a breakpoint?

Disable the breakpoint. from pdb, just type disable N, where N is the breakpoint number you are stuck on. If you don't know the number of your troubling breakpoint, enter tbreak.

How do you set a pdb breakpoint?

Just use python -m pdb <your_script>. py then b <line_number> to set the breakpoint at chosen line number (no function parentheses). Hit c to continue to your breakpoint. You can see all your breakpoints using b command by itself.


1 Answers

Overwrite the function :

old_sys_exit = sys.exit
def new_sys_exit (value) : 
    print "in sys exit %s" % value
    old_sys_exit(value)
sys.exit = new_sys_exit

and then set the breakpoint :

(Pdb) b new_sys_exit

It works, also for other modules that call sys.

like image 196
h4ck3rm1k3 Avatar answered Oct 23 '22 17:10

h4ck3rm1k3