Reputation: 99428
I find there are two ways to invoke pdb.
In OS's shell, run pdb myscript.py
, which invokes pdb immediately and allows to run pdb commands on the running of myscript.py
.
in myscript.py
, import pdb module, and add some function from pdb module in myscript.py
. Then run myscript.py
without pdb as python myscript.py
, and when the running of myscript.py
reaches the first pdb function in myscript.py
, pdb will be invoked, which allows to run pdb commands on the running of myscript.py
.
My questions are:
Are the pdb script (run in a shell in the first way) and the pdb module (imported into myscript.py
in the second way) both in the same script pdb.py
?
In the second way, how is pdb invoked when running a debugged program till a function from pdb module, so that the two ways look the same after invoking pdb?
Upvotes: 1
Views: 304
Reputation: 1514
On my Debian system, various versions of /usr/bin/pdb (including pdb3.5 and pdb2.7) are symlinks pointing at ../lib/python?.?/pdb.py (for the two versions of pdb I mentioned ?.? is 3.5 or 2.7). So for me the module and the script are literally the same file (with two different pathnames). The script conditionally calls pdb.main() in the usual "a python module is a script" manner.
If a debugged python program uses the pdb module without the pdb command, a common way of doing that is to insert a call to pdb.set_trace() in a suitable location (it has the same intent as a pdb breakpoint when using the pdb command).
Another common way of invoking pdb is to use pdb.run; I have used a call to pdb.run within gdb's python interpreter to debug gdb extension code written in python.
Upvotes: 1