classification
Title: pdb raises BdbQuit on 'quit' when started with set_trace
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, giampaolo.rodola, nailor, rmarko, xdegaye
Priority: normal Keywords: patch

Created on 2012-11-08 23:09 by xdegaye, last changed 2014-07-19 21:24 by terry.reedy.

Files
File name Uploaded Description Edit
issue16446.patch nailor, 2013-02-23 20:59
quit.py xdegaye, 2013-02-25 12:07
branch-27.patch xdegaye, 2013-02-25 12:08
Messages (8)
msg175205 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2012-11-08 23:09
Also, the two oldest frames of the stack are identical (sic),
according to the printed traceback.

$ python3 foo.py
> /tmp/foo.py(3)<module>()
-> x = 1
(Pdb) import sys; print(sys.version)
3.2.2 (default, Dec 27 2011, 17:35:55) 
[GCC 4.3.2]
(Pdb) list
  1     import pdb
  2     pdb.set_trace()
  3  -> x = 1
  4
[EOF]
(Pdb) quit
Traceback (most recent call last):
  File "foo.py", line 3, in <module>
    x = 1
  File "foo.py", line 3, in <module>
    x = 1
  File "/usr/local/lib/python3.2/bdb.py", line 46, in trace_dispatch
    return self.dispatch_line(frame)
  File "/usr/local/lib/python3.2/bdb.py", line 65, in dispatch_line
    if self.quitting: raise BdbQuit
bdb.BdbQuit
$
msg176275 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2012-11-24 10:52
See how this is fixed at
http://code.google.com/p/pdb-clone/source/detail?r=8bbac1ffee749fcfd96ea3a2aaca1f240cafc2cc
msg182596 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2013-02-21 15:59
I also bumped into this problem on both 2.7 and 3.3. It is very annoying.
msg182821 - (view) Author: Jyrki Pulliainen (nailor) * Date: 2013-02-23 20:59
I took Xavier's patch and ported in on the 2.7. It'll probably go as is for 3.2. 

The functionality seems to be working and tests pass.
msg182932 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2013-02-25 12:07
There is an error in my patch (already fixed in pdb-clone) and in Jyrki's patch.
Running Jyrki's patch on quit.py produces the following output where the line
number in the last entry of the backtrace is incorrect (should be line 9 instead
of line 7):

$ python quit.py
--Return--
> /tmp/quit.py(4)bar()->None
-> pdb.Pdb().set_trace()
(Pdb) quit
Traceback (most recent call last):
  File "quit.py", line 11, in <module>
    foo()
  File "quit.py", line 7, in foo
    bar()
ZeroDivisionError: integer division or modulo by zero

This problem does not occur when issue 17277 is fixed.
Meanwhile the attached patch, based on Jyrki's patch and based on the 2.7
branch, fixes this.
msg182933 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2013-02-25 12:08
The patch changes the semantics of the quit command: quit behaves like the gdb
detach command when pdb is started with set_trace.
msg219213 - (view) Author: Richard Marko (rmarko) Date: 2014-05-27 10:21
Would be nice to have this commited as without this change

-        if self.quitting:
-            return # None
+        if not self.botframe:
+            self.botframe = frame

it's not possible to quit Bdb (and the code it's executing) as it just returns and doesn't raise BdbQuit.
msg219230 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2014-05-27 17:01
Yes the patch does change the semantics of the quit command:

    * no change when pdb is run as a script or with 'python -m pdb script_name'. As stated in the doc, the 'quit command': "Quit from the debugger. The program being executed is aborted."

    * but when a set_trace() breakpoint is inserted, 'quit' just terminates the debugger and the program continues its execution. It is the purpose of the patch to prevent an inconvenient crash with BdbQuit in that case. The idea is that the hard-coded breakpoint was set to investigate a local problem and one may want to let it run afterwards (for example to check its behavior after having changed some its internal state with pdb).

Sorry, I should have documented that behavior change.
History
Date User Action Args
2014-07-19 22:04:33terry.reedylinkissue21997 superseder
2014-07-19 21:24:34terry.reedysetversions: + Python 3.5, - Python 3.2, Python 3.3
2014-05-27 17:01:22xdegayesetmessages: + msg219230
2014-05-27 10:21:21rmarkosetnosy: + rmarko
messages: + msg219213
2013-02-25 12:08:53xdegayesetfiles: + branch-27.patch

messages: + msg182933
2013-02-25 12:07:22xdegayesetfiles: + quit.py

messages: + msg182932
2013-02-23 20:59:56nailorsetfiles: + issue16446.patch

nosy: + nailor
messages: + msg182821

keywords: + patch
2013-02-21 15:59:35giampaolo.rodolasetmessages: + msg182596
2013-02-21 15:58:31giampaolo.rodolasetnosy: + giampaolo.rodola
2012-11-24 10:52:47xdegayesetmessages: + msg176275
2012-11-15 17:10:39serhiy.storchakasetversions: + Python 3.2, Python 3.3
2012-11-15 15:54:01asvetlovsetnosy: + asvetlov
2012-11-08 23:09:53xdegayecreate