This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pdb: do_debug installs sys.settrace handler when used inside post_mortem
Type: Stage: patch review
Components: Library (Lib) Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: blueyed
Priority: normal Keywords: patch

Created on 2019-03-21 08:28 by blueyed, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 12479 open blueyed, 2019-03-21 09:14
PR 23202 open blueyed, 2020-11-09 02:50
Messages (1)
msg338531 - (view) Author: daniel hahler (blueyed) * Date: 2019-03-21 08:28
It seems like the "debug" command is not properly handled with "post_mortem()".

It appears due to using `sys.settrace(self.trace_dispatch)` in the end of `do_debug`, although no tracing is installed with post_mortem in the first place.


More info:

Given the following test script:

```
def exc():
    raise Exception()


try:
    exc()
except Exception:
    import pdb
    pdb.post_mortem()
```

The behavior with just "quit" is fine:

```
% python3.8 t_pdb.py
> …/project/t_pdb.py(2)exc()
-> raise Exception()
(Pdb) q
```

But when using `debug` inside of it, it will stop at `cmd.postcmd`, and you have to use "continue" twice:

```
% python3.8 t_pdb.py
> …/project/t_pdb.py(2)exc()
-> raise Exception()
(Pdb) debug print(1)
ENTERING RECURSIVE DEBUGGER
> <string>(1)<module>()
((Pdb)) c
1
LEAVING RECURSIVE DEBUGGER
> …/pyenv/3.8-dev/lib/python3.8/cmd.py(159)postcmd()
-> return stop
(Pdb) c
(Pdb) c
```

Also when using `quit` inside of the `debug`:

```
% python3.8 t_pdb.py
> …/project/t_pdb.py(2)exc()
-> raise Exception()
(Pdb) debug print(1)
ENTERING RECURSIVE DEBUGGER
> <string>(1)<module>()
((Pdb)) q
LEAVING RECURSIVE DEBUGGER
> …/pyenv/3.8-dev/lib/python3.8/cmd.py(159)postcmd()
-> return stop
(Pdb) c
(Pdb) c
```

When using `quit` when at `postcmd()` it will even raise `BdbQuit`:

```
% python3.8 t_pdb.py
> …/project/t_pdb.py(2)exc()
-> raise Exception()
(Pdb) debug print(1)
ENTERING RECURSIVE DEBUGGER
> <string>(1)<module>()
((Pdb)) q
LEAVING RECURSIVE DEBUGGER
> …/pyenv/3.8-dev/lib/python3.8/cmd.py(159)postcmd()
-> return stop
(Pdb) q
Traceback (most recent call last):
  File "t_pdb.py", line 6, in <module>
    exc()
  File "t_pdb.py", line 2, in exc
    raise Exception()
Exception

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "t_pdb.py", line 9, in <module>
    pdb.post_mortem()
  File "…/pyenv/3.8-dev/lib/python3.8/pdb.py", line 1626, in post_mortem
    p.interaction(None, t)
  File "…/pyenv/3.8-dev/lib/python3.8/pdb.py", line 352, in interaction
    self._cmdloop()
  File "…/pyenv/3.8-dev/lib/python3.8/pdb.py", line 321, in _cmdloop
    self.cmdloop()
  File "…/pyenv/3.8-dev/lib/python3.8/cmd.py", line 139, in cmdloop
    stop = self.postcmd(stop, line)
  File "…/pyenv/3.8-dev/lib/python3.8/cmd.py", line 159, in postcmd
    return stop
  File "…/pyenv/3.8-dev/lib/python3.8/cmd.py", line 159, in postcmd
    return stop
  File "…/pyenv/3.8-dev/lib/python3.8/bdb.py", line 88, in trace_dispatch
    return self.dispatch_line(frame)
  File "…/pyenv/3.8-dev/lib/python3.8/bdb.py", line 113, in dispatch_line
    if self.quitting: raise BdbQuit
bdb.BdbQuit
```
History
Date User Action Args
2022-04-11 14:59:12adminsetgithub: 80569
2020-11-09 02:50:51blueyedsetpull_requests: + pull_request22102
2019-03-21 09:14:54blueyedsetkeywords: + patch
stage: patch review
pull_requests: + pull_request12431
2019-03-21 08:28:00blueyedcreate