1

I would like to modify the source code of Python 3.4's built in debugger, pdb (I'm assuming it's written in Python). I would like to add some code so that when I put:

pdb.set_trace(locals())

in my code, it invokes the standard pdb interface in the console, and also automatically displays formatted information about my local environment variables similar to the table below.

Can someone point me to the source code for pdb?

-------------------- Objects: -----------------------------------[2000]
[Name: dog]     [Data type: "Dog"]          [2100]
+------+-------+-------+-------+------------+------------+
|  ID  | breed | color |  name |    size    |    uuid    |
+------+-------+-------+-------+------------+------------+
| 2110 |  lynx | black | dog-3 | large!!!!! | e30475ad-9 |
+------+-------+-------+-------+------------+------------+
[Name: cat]     [Data type: "Cat"]          [2200]
+------+-------+-------+---------+------------+
|  ID  | breed | color |   name  |    size    |
+------+-------+-------+---------+------------+
| 2210 |  lynx | black | kitty-5 | large!!!!! |
+------+-------+-------+---------+------------+

-------------------- Lists of Objects: --------------------------[3000]
[Name: cats]     [Data type: "list"]          [3100]
+------+-------+-------+---------+------------+
|  ID  | breed | color |   name  |    size    |
+------+-------+-------+---------+------------+
| 3110 |  lynx | black | kitty-1 | large!!!!! |
| 3120 |  lynx | black | kitty-2 | large!!!!! |
| 3130 |  lynx | black | kitty-3 | large!!!!! |
| 3140 |  lynx | black | kitty-4 | large!!!!! |
| 3150 |  lynx | black | kitty-5 | large!!!!! |
+------+-------+-------+---------+------------+
[Name: dogs]     [Data type: "list"]          [3200]
+------+-------+-------+-------+------------+------------+
|  ID  | breed | color |  name |    size    |    uuid    |
+------+-------+-------+-------+------------+------------+
| 3210 |  lynx | black | dog-1 | large!!!!! | e30475ad-9 |
| 3220 |  lynx | black | dog-2 | large!!!!! | e30475ad-9 |
| 3230 |  lynx | black | dog-3 | large!!!!! | e30475ad-9 |
+------+-------+-------+-------+------------+------------+
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
BitFunny
  • 196
  • 1
  • 10
  • 1
    You know there's a link to the **Source code:** right at the top of [the documentation](https://docs.python.org/3/library/pdb.html), right? It takes you to the online Mercurial repository: https://hg.python.org/cpython/file/3.4/Lib/pdb.py – jonrsharpe Jul 22 '15 at 15:06

1 Answers1

3

pdb is just a normal module that’s shipped as part of the standard library. As such, you can just look into your local lib folder to find the pdb.py source.

Of course, you can also look at it online, e.g. on the Python source repository.

poke
  • 369,085
  • 72
  • 557
  • 602