Skip to content

Commit e654132

Browse files
committed
Update v3/docs/developer-overview.md
1 parent df0eb7e commit e654132

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎v3/docs/developer-overview.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,23 @@ def exec_script_str(script_str, cumulative_mode, finalizer_func):
170170
This code creates a `PGLogger` object then calls its `_runscript` method to run the script passed in as `script_str`.
171171
After execution finishes (possibly due to a bdb-related exception), the `finalize` method is run. This method
172172
does some postprocessing of the trace (`self.trace`) and then calls the user-supplied `finalizer_func`.
173+
174+
`PGLogger` is a subclass of [bdb.Bdb](http://docs.python.org/library/bdb.html#bdb.Bdb),
175+
which is the Python standard debugger module. It stores a ton of fields to record what
176+
is going on as the target program (that the user passed in) executes. Its `_runscript` method
177+
is where the action starts. This method first sets up a sandboxed environment containing a restricted
178+
set of builtins (`user_builtins`) and redirection for stdout (`user_stdout`), and then executes:
179+
180+
```python
181+
try:
182+
self.run(script_str, user_globals, user_globals)
183+
except SystemExit:
184+
raise bdb.BdbQuit
185+
```
186+
187+
The `run` method is actually [inherited from bdb.Bdb](http://docs.python.org/library/bdb.html#bdb.Bdb.run).
188+
It executes the script in a modified global environment (`user_globals`).
189+
190+
Ok, the debugger has just started executing the script that the user has passed in (from `example.py` in our example).
191+
What happens now?
192+

0 commit comments

Comments
 (0)